提交记录 10710


用户 题目 状态 得分 用时 内存 语言 代码长度
GordonLee router32. 测测你的路由器 Accepted 100 2.429 s 43316 KB C++11 536 B
提交时间 评测时间
2019-09-27 14:46:45 2020-08-01 02:20:02
#include "router.h"
#include <arpa/inet.h>
#include <unordered_map>
std::unordered_map<unsigned,unsigned> Map[33];

void init(int n,int q,const RoutingTableEntry *a){
    const RoutingTableEntry *tmp=nullptr;
    for(int i=0;i<n;i++){
        tmp = a + i;
        Map[tmp->len][htonl(tmp->addr)] = tmp->nexthop;
    }

}

unsigned query(unsigned addr){
    addr = htonl(addr);
    for(int len = 32;len>=0;len--){
        if(Map[len].count(addr))
            return Map[len][addr];
        addr &=~(1u << (32-len));
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #115.31 us24 KBAcceptedScore: 25

Testcase #2150.987 ms42 MB + 308 KBAcceptedScore: 25

Testcase #31.29 s42 MB + 308 KBAcceptedScore: 25

Testcase #42.429 s42 MB + 308 KBAcceptedScore: 25


Judge Duck Online | 评测鸭在线
Server Time: 2024-05-08 04:41:19 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用