提交记录 14182


用户 题目 状态 得分 用时 内存 语言 代码长度
andrewfeng router32. 测测你的路由器 Wrong Answer 25 30 s 31704 KB C++ 1022 B
提交时间 评测时间
2020-09-17 18:05:22 2020-09-17 18:05:59
#include "router.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>

std::vector<RoutingTableEntry> table;

int q_num;

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

int checkEqual(unsigned a, unsigned b, int len) {
    // Big Endian
    unsigned temp = 1;
    while (len > 1) {
        temp = temp << 1 + 1;
        --len;
    }
    int cnt = 0;
    if ( (a & temp) != (b & temp)) return 0;
    for (int i = 0; i < 32; ++i) {
        if ( (a & 1) == (b & 1) ) {
            cnt++;
            a >>= 1;
            b >>= 1;
        } else break;
    }
    return cnt;
    
}

unsigned query(unsigned addr) {
    int len = 0;
    unsigned ret_nh;
    for (int i = 0; i < table.size(); ++i) {
        if (checkEqual(addr, table[i].addr, table[i].len) > len) {
            len = checkEqual(addr, table[i].addr, table[i].len);
            ret_nh = table[i].nexthop;
        }
    }

    return ret_nh;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #114.22 us24 KBAcceptedScore: 25

Testcase #216.848 ms30 MB + 984 KBWrong AnswerScore: 0

Testcase #330 s30 MB + 980 KBTime Limit ExceededScore: 0

Testcase #430 s30 MB + 980 KBTime Limit ExceededScore: 0


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