提交记录 10885


用户 题目 状态 得分 用时 内存 语言 代码长度
skylines router32. 测测你的路由器 Wrong Answer 25 301.001 ms 67756 KB C++11 1.14 KB
提交时间 评测时间
2019-10-09 16:21:59 2020-08-01 02:35:35
#include "router.h"
struct Trie{
    struct node{
        node* son[2];
        unsigned via;
    };
    const int id[32]={7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8,23,22,21,20,19,18,17,16,31,30,29,28,27,26,25,24};
    node *root;
    void insert(unsigned addr,int len,unsigned nxt){
        if(root==nullptr)
        {
            root = new node();
        }
        node *tmp=root;
        bool x;
        for(int i=0;i<len;i++)
        {
            x=addr>>id[i]&1;
            if(tmp->son[x]==nullptr)
                tmp->son[x] = new node();
            tmp=tmp->son[x];
        }
        tmp->via=nxt;
    }
    unsigned query(unsigned addr){
        node *tmp=root;
        unsigned ans = 0;
        bool x;
        for(int i=0;i<32;i++)
        {
            x=addr>>id[i]&1;
            if(tmp->son[x]==nullptr) return ans;
            tmp=tmp->son[x];
            if(tmp->via!=0)
                ans=tmp->via;
        }
        return ans;
    }
}trie;
void init(int n, int q, const RoutingTableEntry *a){
    for(int i=0;i<n;i++){
        trie.insert(a[i].addr,a[i].len,a[i].nexthop);
    }
}
unsigned query(unsigned addr){
    return trie.query(addr);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #112.49 us24 KBAcceptedScore: 25

Testcase #246.394 ms66 MB + 172 KBWrong AnswerScore: 0

Testcase #3174.091 ms66 MB + 172 KBWrong AnswerScore: 0

Testcase #4301.001 ms66 MB + 172 KBWrong AnswerScore: 0


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