提交记录 13321


用户 题目 状态 得分 用时 内存 语言 代码长度
lcyxds router32. 测测你的路由器 Wrong Answer 25 140.688 ms 17268 KB C++ 986 B
提交时间 评测时间
2020-08-01 10:28:31 2020-08-01 10:28:34
#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];
	}
	c->end = true;
	c->hop = a.nexthop;
}

void init(int n, int q, const RoutingTableEntry *a) {
	for (int i = 1; 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 #111.27 us24 KBAcceptedScore: 25

Testcase #243.771 ms16 MB + 884 KBWrong AnswerScore: 0

Testcase #392.143 ms16 MB + 884 KBWrong AnswerScore: 0

Testcase #4140.688 ms16 MB + 884 KBWrong AnswerScore: 0


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