提交记录 10699
| 提交时间 |
评测时间 |
| 2019-09-27 10:53:48 |
2020-08-01 02:19:53 |
# 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];
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, nexthop = 0;
for (unsigned i = 0; i < 32; ++ i) {
if (trie_nexthop[current])
nexthop = trie_nexthop[current];
unsigned bit = (addr >> (31ul - i)) & 1ul;
if (trie_childs[current][bit])
current = trie_childs[current][bit];
else break;
}
if (trie_nexthop[current])
nexthop = trie_nexthop[current];
return nexthop;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 12.48 us | 32 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #2 | 30.881 ms | 12 MB + 268 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #3 | 82.662 ms | 12 MB + 268 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #4 | 134.453 ms | 12 MB + 268 KB | Wrong Answer | Score: 0 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2026-03-29 02:43:37 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠