提交记录 14332


用户 题目 状态 得分 用时 内存 语言 代码长度
zhangzj router32. 测测你的路由器 Runtime Error 25 2.416 ms 11792 KB C++ 976 B
提交时间 评测时间
2020-09-23 16:11:59 2020-09-23 16:12:05
#include "router.h"
#include <arpa/inet.h>
#include <unordered_map>

unsigned nexthop_trie[17000000] = {0};
std::unordered_map <unsigned, unsigned> hashmap;

void init(int n, int q, const RoutingTableEntry *a) {
    for (int i = 0; i < n; i++)
    {
        unsigned addr = a[i].addr;
        if (a[i].len == 32)
            hashmap[a[i].addr] = a[i].nexthop;
        else
        {
            int cnt = 0;
            for (int l = a[i].len; l > 0; l -= 8)
            {
                cnt = (cnt << 8) + (addr & 255) + 1;
                addr >>= 8;
            }
            nexthop_trie[cnt] = a[i].nexthop;
        }
    }
}

unsigned query(unsigned addr) {
    if (hashmap.find(addr) != hashmap.end())
        return hashmap[addr];
    int ret = 0;
    int cnt = 0;
    for (int l = 24; l > 0; l -= 8)
    {
        cnt = (cnt << 8) + (addr & 255) + 1;
        addr >>= 8;
        if (nexthop_trie[cnt] != 0)
            ret = nexthop_trie[cnt];
    }
    return ret;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #114.27 us36 KBAcceptedScore: 25

Testcase #22.416 ms11 MB + 528 KBRuntime ErrorScore: 0

Testcase #32.413 ms11 MB + 528 KBRuntime ErrorScore: 0

Testcase #42.413 ms11 MB + 528 KBRuntime ErrorScore: 0


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