提交记录 10831


用户 题目 状态 得分 用时 内存 语言 代码长度
heheda router32. 测测你的路由器 Wrong Answer 50 2.189 s 15720 KB C++11 1020 B
提交时间 评测时间
2019-10-04 10:17:04 2020-08-01 02:31:11
#include "router.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;

map<pair<unsigned, char>, unsigned> table;

void init(int n, int q, const RoutingTableEntry *a) {
	for (int i=0; i<n; i++) {
        RoutingTableEntry x = a[i];
        x.len = 32 - x.len;
        if (x.len != 32) {
            unsigned mask = (-1)^((1<<x.len)-1);
            x.addr &= mask; 
        } else {
            x.addr = 0;
        }
        pair<unsigned, char> pr = make_pair((unsigned)x.addr, x.len);
        if (table.find(pr) == table.end())
            table[pr] = x.nexthop;
    }
}

unsigned query(unsigned addr) {
    for (char i=0; i<=32; i++) {
        if (i != 32) {
            unsigned mask = (-1)^((1<<i)-1);
            addr &= mask;
        } else {
            addr = 0;
        }
        pair<unsigned, char> toSearch = make_pair(addr, i);
        if (table.find(toSearch) != table.end()) {
            return table[toSearch];
        }
    }
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #113.77 us24 KBAcceptedScore: 25

Testcase #2123.46 ms15 MB + 360 KBAcceptedScore: 25

Testcase #31.156 s15 MB + 360 KBWrong AnswerScore: 0

Testcase #42.189 s15 MB + 360 KBWrong AnswerScore: 0


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