提交记录 10317


用户 题目 状态 得分 用时 内存 语言 代码长度
user1 router32. 测测你的路由器 Accepted 100 3.669 s 43332 KB C++11 619 B
提交时间 评测时间
2019-09-17 16:17:45 2020-08-01 02:07:39
#include <unordered_map>
#include <arpa/inet.h>
#include "router.h"

std::unordered_map<unsigned, unsigned> M(888888), G(88888);

void ins(const RoutingTableEntry *e) {
if(e->len==32)
	G[htonl(e->addr)] = e->nexthop; else M[htonl(e->addr)>>32-e->len | 1<<e->len]= e->nexthop; 
}

void init(int n, int q, const RoutingTableEntry *tbl) {
	for (int i = 0; i < n; i++) {
		ins(tbl + i);
	}
}

unsigned query(unsigned addr) {
	addr = htonl(addr); if(G.count(addr)) return G[addr];
	addr = addr>>1 | 0x80000000;
	for (int i = 31; i >= 0; i--) { 
		if (M.count(addr) > 0) {
			return M[addr];
		}
		addr>>=1;
	}
	
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #11.132 ms7 MB + 624 KBAcceptedScore: 25

Testcase #274.79 ms42 MB + 324 KBAcceptedScore: 25

Testcase #31.872 s42 MB + 324 KBAcceptedScore: 25

Testcase #43.669 s42 MB + 324 KBAcceptedScore: 25


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