提交记录 10704


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

# include "router.h"

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

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

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

CompilationN/AN/ACompile OKScore: N/A

Testcase #113.62 us32 KBAcceptedScore: 25

Testcase #233.252 ms12 MB + 268 KBAcceptedScore: 25

Testcase #382.321 ms12 MB + 268 KBWrong AnswerScore: 0

Testcase #4131.344 ms12 MB + 268 KBWrong AnswerScore: 0


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