提交记录 10717


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

# include "router.h"

# include <iostream>

unsigned n_nodes;
unsigned trie_childs[max_entries * 32][2];
unsigned trie_nexthop[max_entries * 32];
bool trie_is_valid[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;
            current = trie_childs[current][bit];
        }
        trie_is_valid[current] = true;
        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];
            if (trie_is_valid[current])
                nexthop = trie_nexthop[current];
        } else break;
    }
    return nexthop;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #135.98 us48 KBAcceptedScore: 25

Testcase #231.834 ms12 MB + 520 KBAcceptedScore: 25

Testcase #380.142 ms12 MB + 520 KBWrong AnswerScore: 0

Testcase #4128.411 ms12 MB + 520 KBWrong AnswerScore: 0


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