提交记录 13328


用户 题目 状态 得分 用时 内存 语言 代码长度
imalyd router32. 测测你的路由器 Accepted 100 319.241 ms 67760 KB C++ 788 B
提交时间 评测时间
2020-08-01 10:38:26 2020-08-01 10:38:28
#include <arpa/inet.h>
#include "router.h"
struct TrieNode{
	unsigned nexthop;
	unsigned is;
	unsigned padding1;
	unsigned padding2;
	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;
		unsigned int ad=htonl(i->addr);
		for(char l=31,r=31-i->len;l!=r;--l){
			if(ad>>l&1){
				if(v->c1)v=v->c1;
				else v=v->c1=++t;
			}else{
				if(v->c0)v=v->c0;
				else v=v->c0=++t;
			}
		}
		v->is=1;
		v->nexthop=i->nexthop;
	}
}
unsigned query(unsigned addr) {
	unsigned cur=0,ad=htonl(addr);
	TrieNode *v=T;
	if(v->is)cur=v->nexthop;
	for(char l=31;~l;--l){
		if(ad>>l&1)v=v->c1;else v=v->c0;
		if(v){if(v->is)cur=v->nexthop;}
		else return cur;
	}
	return cur;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #113.03 us28 KBAcceptedScore: 25

Testcase #246.841 ms66 MB + 176 KBAcceptedScore: 25

Testcase #3183.197 ms66 MB + 176 KBAcceptedScore: 25

Testcase #4319.241 ms66 MB + 176 KBAcceptedScore: 25


Judge Duck Online | 评测鸭在线
Server Time: 2024-05-08 03:38:13 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用