提交记录 13333


用户 题目 状态 得分 用时 内存 语言 代码长度
Tweetuzki router32. 测测你的路由器 Wrong Answer 25 112.039 ms 12556 KB C++ 797 B
提交时间 评测时间
2020-08-01 10:53:46 2020-08-01 10:53:48
#include "router.h"

namespace trie {

const unsigned MaxN = 2827088;

unsigned cnt;
unsigned ch[MaxN * 32 + 5][2];
unsigned val[MaxN * 32 + 5];

inline void insert(unsigned addr, unsigned char len, unsigned nexthop) {
  unsigned u = 0;
  for (int i = 31; i >= 32 - len; --i) {
    unsigned c = (addr >> i) & 1;
    if (ch[u][c] == 0) ch[u][c] = ++cnt;
    u = ch[u][c];
  }
  val[u] = nexthop;
}

inline unsigned query(unsigned addr) {
  int u = 0;
  for (int i = 31; i >= 0; --i) {
    unsigned c = (addr >> i) & 1;
    if (ch[u][c] == 0) return 0;
    u = ch[u][c];
  }
  return val[u];
}

}

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.04 us32 KBAcceptedScore: 25

Testcase #230.998 ms12 MB + 268 KBWrong AnswerScore: 0

Testcase #371.523 ms12 MB + 268 KBWrong AnswerScore: 0

Testcase #4112.039 ms12 MB + 268 KBWrong AnswerScore: 0


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