提交记录 32023
| 提交时间 |
评测时间 |
| 2026-08-14 10:22:41 |
2026-08-14 10:23:29 |
#include "router.h"
#include <stdlib.h>
#include <string.h>
static unsigned *ch0, *ch1, *nh; // nh stores (nexthop+1), 0 = none
static unsigned cnt;
void init(int n, int q, const RoutingTableEntry *a) {
size_t maxn = (size_t)n * 33 + 2;
ch0 = (unsigned*)malloc(maxn * sizeof(unsigned));
ch1 = (unsigned*)malloc(maxn * sizeof(unsigned));
nh = (unsigned*)malloc(maxn * sizeof(unsigned));
memset(ch0, 0, maxn * sizeof(unsigned));
memset(ch1, 0, maxn * sizeof(unsigned));
memset(nh, 0, maxn * sizeof(unsigned));
cnt = 1; // root = node 1
for (int i = 0; i < n; i++) {
unsigned ip = __builtin_bswap32(a[i].addr);
unsigned len = a[i].len;
unsigned h = a[i].nexthop;
unsigned node = 1;
for (unsigned b = 0; b < len; b++) {
unsigned bit = (ip >> (31 - b)) & 1u;
unsigned *c = bit ? &ch1[node] : &ch0[node];
if (*c == 0) *c = ++cnt;
node = *c;
}
nh[node] = h + 1;
}
}
unsigned query(unsigned addr) {
unsigned ip = __builtin_bswap32(addr);
unsigned node = 1, best = nh[1];
for (int b = 0; b < 32; b++) {
unsigned bit = (ip >> (31 - b)) & 1u;
unsigned c = bit ? ch1[node] : ch0[node];
if (c == 0) break;
node = c;
unsigned h = nh[node];
if (h) best = h;
}
return best ? best - 1 : 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 15.04 us | 24 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #2 | 88.288 ms | 321 MB + 864 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #3 | 235.369 ms | 321 MB + 864 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #4 | 381.728 ms | 321 MB + 864 KB | Accepted | Score: 25 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2026-09-12 04:42:07 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠