提交记录 14332
| 提交时间 |
评测时间 |
| 2020-09-23 16:11:59 |
2020-09-23 16:12:05 |
#include "router.h"
#include <arpa/inet.h>
#include <unordered_map>
unsigned nexthop_trie[17000000] = {0};
std::unordered_map <unsigned, unsigned> hashmap;
void init(int n, int q, const RoutingTableEntry *a) {
for (int i = 0; i < n; i++)
{
unsigned addr = a[i].addr;
if (a[i].len == 32)
hashmap[a[i].addr] = a[i].nexthop;
else
{
int cnt = 0;
for (int l = a[i].len; l > 0; l -= 8)
{
cnt = (cnt << 8) + (addr & 255) + 1;
addr >>= 8;
}
nexthop_trie[cnt] = a[i].nexthop;
}
}
}
unsigned query(unsigned addr) {
if (hashmap.find(addr) != hashmap.end())
return hashmap[addr];
int ret = 0;
int cnt = 0;
for (int l = 24; l > 0; l -= 8)
{
cnt = (cnt << 8) + (addr & 255) + 1;
addr >>= 8;
if (nexthop_trie[cnt] != 0)
ret = nexthop_trie[cnt];
}
return ret;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 14.27 us | 36 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #2 | 2.416 ms | 11 MB + 528 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #3 | 2.413 ms | 11 MB + 528 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #4 | 2.413 ms | 11 MB + 528 KB | Runtime Error | Score: 0 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2026-03-22 18:03:13 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠