QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#354865#2495. Knight's MoveEnergy_is_not_overCompile Error//C++142.4kb2024-03-16 06:17:182024-03-16 06:17:19

Judging History

你现在查看的是最新测评结果

  • [2024-03-16 06:17:19]
  • 评测
  • [2024-03-16 06:17:18]
  • 提交

answer

struct VertexInfo {
  int pr, nxt, jump;
  VertexInfo(int v): pr(v), nxt(v), jump(v) {}
};
struct PathHolder {
  const int jump_sz;
  vector<VertexInfo> a;
  PathHolder(int n): jump_sz(sqrt(n) + 0.47) {
    a.assign(n, 0);
    iota(a.begin(), a.end(), 0);
  }
  void delEdge(int u, int v) {
    a[v].pr = v;
    a[u].nxt = u;
    for (int i = 0, x = u; i < jump_sz; ++i) {
      a[x].jump = u, x = a[x].pr;
    }
  }
  void addEdge(int u, int v) {
    a[u].nxt = v;
    a[v].pr = u;
    int x = u, steps = 0;
    while (steps + 1 < jump_sz && x != a[x].pr) {
      x = a[x].pr;
      ++steps;
    }
    int f = u;
    while ((++steps) <= jump_sz) f = a[f].nxt;
    for (; x != u; x = a[x].nxt, f = a[f].nxt) {
      a[x].jump = f;
    }
    a[x].jump = f;
  }
  int getRoot(int v) const {
    while (v != a[v].jump) v = a[v].jump;
    return v;
  }
  VertexInfo& operator [](int v) { return a[v]; }
  bool in(int v) const { return v != a[v].pr; }
  bool out(int v) const { return v != a[v].nxt; }
};
vector<int> HF(int n, vector<pair<int, int>> e) {
  int ops = 4e6, fails = 0, tot = 0;
  PathHolder p(n);
  mt19937 gen(time(0) + clock());
  vector<vector<int>> g(n), rg(n);
  for (auto p : e) {
    g[p.first].push_back(p.second);
    rg[p.second].push_back(p.first);
  }
  vector<int> s(n), t(n);
  iota(s.begin(), s.end(), 0);
  iota(t.begin(), t.end(), 0);
  while (fails < ops / 20 && (n == 1 || !e.empty())) {
    e.clear();
    erase_if(s, [&](int v) {return p.in(v);});
    erase_if(t, [&](int v) {return p.out(v);});
    for (int to : s) for (int from : rg[to])
      if (p.out(from)) e.push_back({from, to});
    for (int from : t) for (int to : g[from])
      e.push_back({from, to});
    shuffle(e.begin(), e.end(), gen);
    for (auto [u, v] : e) {
      --ops, ++fails;
      if ((p.out(u) && p.in(v))) continue;
      if (p.getRoot(u) == p.getRoot(v)) continue;
      if ((p.out(u) || p.in(v)) && gen() % 2)
        continue;
      if (p.out(u)) {
        s.push_back(p[u].nxt);
        p.delEdge(u, p[u].nxt);
      } else if (p.in(v)) {
        t.push_back(p[v].pr);
        p.delEdge(p[v].pr, v);
      } else ++tot, fails = 0;
      p.addEdge(u, v);
    }
    if (tot + 1 == n) {
      int v = p.getRoot(0);
      vector<int> res;
      for (int i = 0; i < n; ++i, v = p[v].pr)
        res.push_back(v);
      return {res.rbegin(), res.rend()};
    }
  }
  return {};
}

Details

answer.code:7:3: error: ‘vector’ does not name a type
    7 |   vector<VertexInfo> a;
      |   ^~~~~~
answer.code: In constructor ‘PathHolder::PathHolder(int)’:
answer.code:8:30: error: ‘sqrt’ was not declared in this scope
    8 |   PathHolder(int n): jump_sz(sqrt(n) + 0.47) {
      |                              ^~~~
answer.code:9:5: error: ‘a’ was not declared in this scope
    9 |     a.assign(n, 0);
      |     ^
answer.code:10:5: error: ‘iota’ was not declared in this scope
   10 |     iota(a.begin(), a.end(), 0);
      |     ^~~~
answer.code: In member function ‘void PathHolder::delEdge(int, int)’:
answer.code:13:5: error: ‘a’ was not declared in this scope
   13 |     a[v].pr = v;
      |     ^
answer.code: In member function ‘void PathHolder::addEdge(int, int)’:
answer.code:20:5: error: ‘a’ was not declared in this scope
   20 |     a[u].nxt = v;
      |     ^
answer.code: In member function ‘int PathHolder::getRoot(int) const’:
answer.code:35:17: error: ‘a’ was not declared in this scope
   35 |     while (v != a[v].jump) v = a[v].jump;
      |                 ^
answer.code: In member function ‘VertexInfo& PathHolder::operator[](int)’:
answer.code:38:43: error: ‘a’ was not declared in this scope
   38 |   VertexInfo& operator [](int v) { return a[v]; }
      |                                           ^
answer.code: In member function ‘bool PathHolder::in(int) const’:
answer.code:39:38: error: ‘a’ was not declared in this scope
   39 |   bool in(int v) const { return v != a[v].pr; }
      |                                      ^
answer.code: In member function ‘bool PathHolder::out(int) const’:
answer.code:40:39: error: ‘a’ was not declared in this scope
   40 |   bool out(int v) const { return v != a[v].nxt; }
      |                                       ^
answer.code: At global scope:
answer.code:42:1: error: ‘vector’ does not name a type
   42 | vector<int> HF(int n, vector<pair<int, int>> e) {
      | ^~~~~~