提交记录 13317


用户 题目 状态 得分 用时 内存 语言 代码长度
lcyxds router32. 测测你的路由器 Wrong Answer 25 142.817 ms 17268 KB C++ 1009 B
提交时间 评测时间
2020-08-01 10:22:17 2020-08-01 10:22:20
#include "router.h"

/*
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;
	int hop;
	Node* next[2];
};

Node* _root = new Node;

void Insert(RoutingTableEntry a) {
	Node* c = _root;
	int solo;
	for (int i = 1; i <= a.len; i++) {
		solo = a.addr>>(32-i)&1;
		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];
		if (i==a.len) {
			c->end = true;
			c->hop = a.nexthop;
		}
	}
}

void init(int n, int q, const RoutingTableEntry *a) {
	for (int i = 0; i < n; i++) {
		Insert(a[i]);
	}
}

unsigned query(unsigned addr) {
	int res = 0;
	Node* c = _root;
	int solo;
	for (int i = 1; i <= 32; i++) {
		solo = addr>>(32-i)&1;
		c = c->next[solo];
		if (!c) return res;
		if (c->end) {
			res = c->hop;
		}
	}
	return res;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #112.96 us24 KBAcceptedScore: 25

Testcase #246.924 ms16 MB + 884 KBWrong AnswerScore: 0

Testcase #395.08 ms16 MB + 884 KBWrong AnswerScore: 0

Testcase #4142.817 ms16 MB + 884 KBWrong AnswerScore: 0


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