提交记录 11275


用户 题目 状态 得分 用时 内存 语言 代码长度
function2 router32. 测测你的路由器 Wrong Answer 25 359.458 ms 97712 KB C++11 1.25 KB
提交时间 评测时间
2019-11-12 10:58:20 2020-08-01 02:41:12
#include <stdint.h>
#include <cstdlib>
#include <utility>
#include <iostream>
#include "router.h"

struct Trie {
    struct node_t {
        node_t *ch[2];
        RoutingTableEntry *entry;

        node_t() {
            ch[0] = ch[1] = nullptr;
            entry = nullptr;
        }
    };
    node_t *root = nullptr;

    void insert(const RoutingTableEntry& entry) {
        if (!root) root = new node_t;
        auto u = root;
        for (int i = 0; i < entry.len; i++) {
            auto &v = u->ch[entry.addr >> i & 1];
            if (!v) v = new node_t;
            u = v;
        }
        delete u->entry;
        u->entry = new RoutingTableEntry(entry);
    }

    const RoutingTableEntry *query(uint32_t addr) {
        if (!root) return nullptr;
        auto u = root;
        const RoutingTableEntry *ret = nullptr;
        for (int i = 0; i < 32; i++) {
            u = u->ch[addr >> i & 1];
            if (!u) break;
            if (u->entry) {
                ret = u->entry;
            }
        }
        return ret;
    }
};
static Trie trie;

void init(int n, int q, const RoutingTableEntry *a) {
	for (int i = 0; i < n; i++) trie.insert(a[i]);
}

unsigned query(unsigned addr) {
	auto entry = trie.query(addr);
    return entry ? entry->nexthop : 0u;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #134.17 us36 KBAcceptedScore: 25

Testcase #258.168 ms95 MB + 432 KBWrong AnswerScore: 0

Testcase #3209.37 ms95 MB + 432 KBWrong AnswerScore: 0

Testcase #4359.458 ms95 MB + 432 KBWrong AnswerScore: 0


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