提交记录 10745
| 提交时间 |
评测时间 |
| 2019-09-28 19:39:23 |
2020-08-01 02:25:47 |
//#define Debug
#ifndef Debug
#include "router.h"
#include <netinet/in.h>
#endif
#ifdef Debug
typedef struct {
unsigned addr;
unsigned char len;
char pad[3]; // Padding for memory alignment
unsigned nexthop;
} __attribute__((packed)) RoutingTableEntry;
#endif
#include <iostream>
#include <cstdlib>
unsigned ones_prefix[33];
unsigned mask_addr[33];
unsigned int ans=-1;
int maxlen=-1;
int n;
int q;
RoutingTableEntry *a;
void init(int _n, int _q, const RoutingTableEntry *_a) {
n=_n;
q=_q;
a=(RoutingTableEntry*)_a;
for (int i=1;i<=32;i++){
ones_prefix[i]=ones_prefix[i-1]|(1<<(32-i));
}
for (int i=0;i<n;i++){
a[i].addr=htonl(a[i].addr);
a[i].addr&=ones_prefix[a[i].len];
}
}
unsigned query(unsigned addr) {
addr=htonl(addr);
for (int i=1;i<=32;i++){
mask_addr[i]=addr&ones_prefix[i];
}
for (int i=0;i<n;i++){
if ((mask_addr[a[i].len]==a[i].addr)&&(a[i].len>maxlen)){
maxlen=a[i].len;
ans=a[i].nexthop;
}
}
if (maxlen==-1) return 0;
return ans;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 37.06 us | 36 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #2 | 3.804 ms | 9 MB + 512 KB | Accepted | Score: 25 | 显示更多 |
| Testcase #3 | 30 s | 9 MB + 508 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #4 | 30 s | 9 MB + 508 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2026-03-29 01:18:47 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠