提交记录 10740
| 提交时间 |
评测时间 |
| 2019-09-28 19:20:51 |
2020-08-01 02:25:14 |
//#define Debug
#ifndef Debug
#include "router.h"
#endif
#ifdef Debug
typedef struct {
unsigned addr;
unsigned char len;
char pad[3]; // Padding for memory alignment
unsigned nexthop;
} __attribute__((packed)) RoutingTableEntry;
#endif
#include <iostream>
#include <cstdlib>
unsigned ones_prefix[33];
unsigned mask_addr[33];
int maxlen=-1;
int n;
int q;
RoutingTableEntry *a;
struct trie_node
{
unsigned nexthop;
trie_node* son[2];
};
trie_node* root=new trie_node;
void insert_node(unsigned addr,unsigned len,unsigned nexthop){
trie_node* tmp_node=root;
for (unsigned i=0;i<len;i++){
int dir=((addr&(1<<(31-i)))>0);
if (tmp_node->son[dir]==NULL){
tmp_node->son[dir]=new trie_node;
tmp_node=tmp_node->son[dir];
tmp_node->son[0]=tmp_node->son[1]=NULL;
tmp_node->nexthop=0;
}
else{
tmp_node=tmp_node->son[dir];
}
}
tmp_node->nexthop=nexthop;
}
void init(int _n, int _q, const RoutingTableEntry *_a) {
n=_n;
q=_q;
a=(RoutingTableEntry*)_a;
for (int i=1;i<=32;i++){
ones_prefix[i]=ones_prefix[i-1]|(1<<(32-i));
}
root->son[0]=root->son[1]=NULL;
root->nexthop=0;
for (int i=0;i<n;i++){
insert_node(a[i].addr,a[i].len,a[i].nexthop);
}
}
unsigned query(unsigned addr) {
trie_node* tmp_node=root;
unsigned ans=root->nexthop;
for (int i=0;i<32;i++){
int dir=((addr&(1<<(31-i)))>0);
if (tmp_node->son[dir]==NULL){
break;
}
tmp_node=tmp_node->son[dir];
if (tmp_node->nexthop!=0){
ans=tmp_node->nexthop;
}
}
return ans;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 34.69 us | 36 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #2 | 46.147 ms | 16 MB + 896 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #3 | 99.002 ms | 16 MB + 896 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #4 | 151.467 ms | 16 MB + 896 KB | Wrong Answer | Score: 0 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2026-03-29 01:07:04 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠