提交记录 10714


用户 题目 状态 得分 用时 内存 语言 代码长度
lyricz router32. 测测你的路由器 Wrong Answer 50 129.636 ms 12556 KB C++ 1.15 KB
提交时间 评测时间
2019-09-27 15:10:13 2020-08-01 02:20:06
# define max_entries 827088ul

# include "router.h"

unsigned n_nodes;
unsigned trie_childs[max_entries * 32][2];
unsigned trie_nexthop[max_entries * 32];

void init(int n, int q, const RoutingTableEntry *a) {
    RoutingTableEntry *routing_table = (RoutingTableEntry*) a;
    for (int i = 0; i < n; ++ i) {
        unsigned bit, current = 0;
        unsigned addr = routing_table[i].addr, length = routing_table[i].len;
        for (unsigned j = 0; j < length; ++ j) {
            bit = (addr >> (31ul - j)) & 1ul;
            if (!trie_childs[current][bit]) {
                trie_childs[current][bit] = ++ n_nodes;
                trie_nexthop[n_nodes] = trie_nexthop[current];
            }
            current = trie_childs[current][bit];
        }
        trie_nexthop[current] = routing_table[i].nexthop;
    }
}

unsigned query(unsigned addr) {
    unsigned current = 0, bit, nexthop = trie_nexthop[0];
    for (unsigned i = 0; i < 32; ++ i) {
        bit = (addr >> (31ul - i)) & 1ul;
        if (trie_childs[current][bit]) {
            current = trie_childs[current][bit];
            nexthop = trie_nexthop[current];
        } else break;
    }
    return nexthop;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #112.72 us32 KBAcceptedScore: 25

Testcase #231.204 ms12 MB + 268 KBAcceptedScore: 25

Testcase #380.436 ms12 MB + 268 KBWrong AnswerScore: 0

Testcase #4129.636 ms12 MB + 268 KBWrong AnswerScore: 0


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