提交记录 10698


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

#include "router.h"

int n_entries, n_nodes;
unsigned trie_childs[max_entries * 32][2];
unsigned trie_nexthop[max_entries * 32];
unsigned one_bit_prefix[33], addr_mask[33];
RoutingTableEntry *routing_table;

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

unsigned query(unsigned addr) {
    unsigned current = 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
            return trie_nexthop[current];
    }
    return trie_nexthop[current];
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #111.92 us32 KBAcceptedScore: 25

Testcase #230.907 ms12 MB + 268 KBWrong AnswerScore: 0

Testcase #375.645 ms12 MB + 268 KBWrong AnswerScore: 0

Testcase #4120.373 ms12 MB + 268 KBWrong AnswerScore: 0


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