提交记录 10779


用户 题目 状态 得分 用时 内存 语言 代码长度
duck router32. 测测你的路由器 Wrong Answer 50 3.043 s 48488 KB C++ 1010 B
提交时间 评测时间
2019-09-30 00:52:37 2020-08-01 02:29:27
#include <map>
#include <arpa/inet.h>
#include "router.h"
#include <algorithm>

std::map<unsigned, unsigned> M[33];

void ins(const RoutingTableEntry *e) {
    M[e->len][e->addr] = e->nexthop;
}

int nn;
const RoutingTableEntry *a;
void init(int n, int q, const RoutingTableEntry *tbl) {
    nn=n;a=tbl;
    for (int i = 0; i < n; i++) {
        ins(tbl + i);
    }
}
bool cmp(const RoutingTableEntry &u, const RoutingTableEntry &v){
    return u.addr<v.addr;
}
unsigned query(unsigned addr) {
    unsigned addr0=addr;
    addr = htonl(addr);

    for (int i = 32; i >= 0; i--) {
        RoutingTableEntry tmp;
        tmp.addr=addr0;
        int lo=std::lower_bound(a,a+nn,tmp,cmp)-a;
        int hi=std::upper_bound(a,a+nn,tmp,cmp)-a;
        for (int j=lo;j<hi;j++){
            if (a[j].addr==addr0 && a[j].len==i){
                return a[j].nexthop;
            }
        }
        addr &= ~(1u << (32 - i));
        addr0&=~(1u<<((i-1)/8*8+7-(i-1)%8));
        addr=htonl(addr0);
    }

    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #113.53 us24 KBAcceptedScore: 25

Testcase #2325.76 ms47 MB + 360 KBAcceptedScore: 25

Testcase #31.687 s47 MB + 360 KBWrong AnswerScore: 0

Testcase #43.043 s47 MB + 360 KBWrong AnswerScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-03-28 23:25:45 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠