提交记录 10718
提交时间 |
评测时间 |
2019-09-27 16:06:25 |
2020-08-01 02:20:21 |
# define max_entries 827088ul
# include "router.h"
# include <arpa/inet.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 = htonl(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) {
addr = htonl(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;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 35.48 us | 48 KB | Accepted | Score: 25 | 显示更多 |
Testcase #2 | 36.808 ms | 32 MB + 548 KB | Accepted | Score: 25 | 显示更多 |
Testcase #3 | 151.84 ms | 32 MB + 548 KB | Accepted | Score: 25 | 显示更多 |
Testcase #4 | 265.888 ms | 32 MB + 548 KB | Accepted | Score: 25 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:36:01 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠