提交记录 13273


用户 题目 状态 得分 用时 内存 语言 代码长度
imalyd router32. 测测你的路由器 Wrong Answer 25 151.224 ms 596072 KB C++ 739 B
提交时间 评测时间
2020-08-01 09:24:13 2020-08-01 09:24:16
#include "router.h"
struct TrieNode{
	unsigned nexthop;
	unsigned padding1;
	unsigned padding2;
	unsigned padding3;
	TrieNode *c0;
	TrieNode *c1;
}T[26466817];
void init(int n, int q, const RoutingTableEntry *a) {
	TrieNode *t=T;
	for(const RoutingTableEntry *i=a,*e=a+n;i!=e;++i){
		TrieNode *v=T;
		for(char l=31,r=31-i->len;l!=r;--l){
			unsigned char c=(i->addr)>>l;
			if(c){
				if(v->c1)v=v->c1;
				else v=v->c1=++t;
			}else{
				if(v->c0)v=v->c0;
				else v=v->c1=++t;
			}
		}
		v->nexthop=i->nexthop;
	}
}

unsigned query(unsigned addr) {
	unsigned cur=0;
	TrieNode *v=T;
	for(char l=31;~l;--l){
		unsigned char c=addr>>l;
		if(c)v=v->c1;else v=v->c0;
		if(v){if(v->nexthop)cur=v->nexthop;}
		else return cur;
	}
	return cur;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #112.68 us28 KBAcceptedScore: 25

Testcase #2102.308 ms582 MB + 104 KBWrong AnswerScore: 0

Testcase #3126.047 ms582 MB + 104 KBWrong AnswerScore: 0

Testcase #4151.224 ms582 MB + 104 KBWrong AnswerScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-03-24 15:07:03 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠