提交记录 13356
| 提交时间 |
评测时间 |
| 2020-08-01 11:35:59 |
2020-08-01 11:36:01 |
#include "router.h"
#include <iostream>
/*
typedef struct {
unsigned addr;
unsigned char len;
char pad[3]; // Padding for memory alignment
unsigned nexthop;
} __attribute__((packed)) RoutingTableEntry;
*/
using namespace std;
struct Node {
bool end;
unsigned hop;
Node* next[2];
};
Node* _root = new Node;
void Insert(RoutingTableEntry a) {
// cout << "Insert " << a.addr << endl;
Node* c = _root;
int solo;
for (int i = 1; i <= (int)a.len; i++) {
solo = a.addr>>(32-i)&1;
// cout << i << ',' << solo << endl;
if (!c->next[solo]) {
c->next[solo] = new Node;
c->next[solo]->end = false;
c->next[solo]->next[0] = 0;
c->next[solo]->next[1] = 0;
}
c = c->next[solo];
}
c->end = true;
c->hop = a.nexthop;
// cout << "Insertion end" << endl;
}
//RoutingTableEntry Input() {
// RoutingTableEntry a;
// unsigned x, y, z;
// cin >> hex >> x >> dec >> y >> z;
// a.addr = x;
// a.len = y;
// a.nexthop = z;
// return a;
//}
void init(int n, int q, const RoutingTableEntry *a) {
_root->end = false;
_root->next[0] = 0;
_root->next[1] = 0;
for (int i = 0; i < n; i++) {
Insert(a[i]);
}
// cout << "init end" << endl;
}
unsigned query(unsigned addr) {
// cout << "Query " << addr << endl;
unsigned res = 0;
Node* c = _root;
int solo;
if (c->end) {
res = c->hop;
}
for (int i = 1; i <= 32; i++) {
solo = addr>>(32-i)&1;
// cout << i << ',' << solo << endl;
c = c->next[solo];
if (!c) return res;
if (c->end) {
res = c->hop;
}
}
return res;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 34.08 us | 36 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #2 | 43.938 ms | 16 MB + 896 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #3 | 92.818 ms | 16 MB + 896 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #4 | 141.331 ms | 16 MB + 896 KB | Wrong Answer | Score: 0 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2026-03-24 12:13:07 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠