提交记录 10867
| 提交时间 |
评测时间 |
| 2019-10-06 20:57:53 |
2020-08-01 02:35:18 |
#include "router.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <map>
#include <arpa/inet.h>
using namespace std;
map<pair<unsigned, char>, unsigned> table;
void init(int n, int q, const RoutingTableEntry *a) {
for (int i=0; i<n; i++) {
RoutingTableEntry x = a[i];
x.addr = htonl(x.addr);
x.len = 32 - x.len;
if (x.len != 32) {
unsigned mask = (-1)^((1<<x.len)-1);
x.addr &= mask;
} else {
x.addr = 0;
}
pair<unsigned, char> pr = make_pair((unsigned)x.addr, x.len);
if (table.find(pr) == table.end())
table[pr] = x.nexthop;
}
}
unsigned query(unsigned addr) {
addr = htonl(addr);
for (char i = 0; i <= 32; i++)
{
if (i != 32) {
unsigned mask = (-1)^((1<<i)-1);
addr &= mask;
} else {
addr = 0;
}
pair<unsigned, char> toSearch = make_pair(addr, i);
if (table.find(toSearch) != table.end()) {
return table[toSearch];
}
}
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 12.82 us | 24 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #2 | 144.677 ms | 59 MB + 996 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #3 | 1.717 s | 59 MB + 996 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #4 | 3.293 s | 59 MB + 996 KB | Accepted | Score: 25 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2026-03-28 19:51:19 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠