提交记录 14698


用户 题目 状态 得分 用时 内存 语言 代码长度
test router32. 测测你的路由器 Runtime Error 25 28.986 ms 53580 KB C++ 1.25 KB
提交时间 评测时间
2020-11-02 00:24:32 2020-11-02 00:24:35
#include "router.h"
#include <arpa/inet.h>
#include <list>
#include <iostream>
using namespace std;

struct node{
  list<RoutingTableEntry> children[65537];
  node(){}
};

node nodes[16]; //17-32./checksum < data/checksum_input1.pcap
list<RoutingTableEntry> small[65547]; //1-16

void init(int n, int q, const RoutingTableEntry *a) {
	for(int i=0;i<n;i++){
		int addr = ntohl(a[i].addr);
		int len = a[i].len;
		if(len<17){
	      int index = (addr >> (32-len));
	      for(list<RoutingTableEntry>::iterator it = small[index].begin();it!=small[index].end();++it){
	          if((*it).len == len){
	              small[index].erase(it);
	              break;
	          }
	      }
	      small[index].push_back(a[i]);
	    }
	    else{
	      int index = addr >> 16;
	      int r = (addr & 0xffff) >> (32 - len);
	      for(list<RoutingTableEntry>::iterator it = nodes[len-17].children[index].begin();it!=nodes[len-17].children[index].end();++it){
	          int taddr = (*it).addr;
	          if((len == ((*it).len & 0xff)) && ((taddr & 0xffff) >> (32-len)) == r){
	              nodes[len-17].children[index].erase(it);
	              break;
	          }
	      }
	      nodes[len-17].children[index].push_back(a[i]);
	    }
	} 
}

unsigned query(unsigned addr) {
  return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #14.675 ms25 MB + 548 KBAcceptedScore: 25

Testcase #228.961 ms52 MB + 332 KBRuntime ErrorScore: 0

Testcase #328.986 ms52 MB + 332 KBRuntime ErrorScore: 0

Testcase #428.961 ms52 MB + 332 KBRuntime ErrorScore: 0


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