提交记录 10865


用户 题目 状态 得分 用时 内存 语言 代码长度
ta123 router32. 测测你的路由器 Time Limit Exceeded 50 30 s 9716 KB C++11 794 B
提交时间 评测时间
2019-10-06 19:49:51 2020-08-01 02:35:10
#include "router.h"
#include <cstdio>
#include <arpa/inet.h>

int n;
const RoutingTableEntry *a;

void init(int _n, int _q, const RoutingTableEntry *_a)
{
    n = _n, a = (RoutingTableEntry *)_a;
}

unsigned query(unsigned addr)
{
    addr = htonl(addr);
    unsigned table_addr = 0;
    unsigned nexthop = 0;
    int len = -1;
    // for (int i = n; i--;)
    for (int i = 0; i < n; ++i)
        if (a[i].len == 0 && len == -1)
            nexthop = a[i].nexthop, len = 0;
        else if ((len == -1 || a[i].len > len) && ((addr ^ htonl(a[i].addr)) & -(1 << 32 - a[i].len)) == 0)
        {
            nexthop = a[i].nexthop, len = a[i].len;
            table_addr = htonl(a[i].addr);
        }
    // printip("table_addr", table_addr);
    // printf("len = %d\n", len);
    return nexthop;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #113.02 us24 KBAcceptedScore: 25

Testcase #23.438 ms9 MB + 500 KBAcceptedScore: 25

Testcase #330 s9 MB + 496 KBTime Limit ExceededScore: 0

Testcase #430 s9 MB + 496 KBTime Limit ExceededScore: 0


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