Submission #493592

# Submission time Handle Problem Language Result Execution time Memory
493592 2021-12-12T09:55:14 Z 600Mihnea Monster Game (JOI21_monster) C++17
0 / 100
92 ms 284 KB
#include <bits/stdc++.h>
#include "monster.h"

using namespace std;

vector<int> Solve(int n) {
  /// Initial sort

  function<vector<int>(int, int)> mrg = [&] (int l, int r) {
    if (l == r) {
      vector<int> v = {l};
      return v;
    }
    int m = (l + r) / 2;
    vector<int> a = mrg(l, m);
    vector<int> b = mrg(m + 1, r);
    vector<int> c;
    c.reserve(r - l + 1);
    int pa = 0, pb = 0;
    while (pa < (int) a.size() && pb < (int) b.size()) {
      if (Query(a[pa], b[pb])) {
        c.push_back(a[pa++]);
      } else {
        c.push_back(b[pb++]);
      }
    }
    while (pa < (int) a.size()) {
      c.push_back(a[pa++]);
    }
    while (pb < (int) b.size()) {
      c.push_back(b[pb++]);
    }
    return c;
  };

  vector<int> v = mrg(0, n - 1);


  int k = min(n, 13);

  vector<int> cnt(k, 0);


  for (int i = 0; i < k; i++) {
    for (int j = 0; j < k; j++) {
      if (i != j) {
        cnt[i] += !Query(v[i], v[j]);
      }
    }
  }

  int mn = cnt[0];

  vector<int> wmn;

  for (int i = 1; i < k; i++) {
    mn = min(mn, cnt[i]);
  }

  for (int i = 0; i < k; i++) {
    if (mn == cnt[i]) {
      wmn.push_back(i);
    }
  }
  assert((int) wmn.size() == 2);

  int pos = wmn[1];


  if (!Query(v[wmn[0]], v[wmn[1]])) {
    pos = wmn[0];
  }

  vector<int> rl;
  for (int i = pos; i >= 0; i--) {
    rl.push_back(v[i]);
  }
  int last = 0;
  int l = pos + 1;
  while (l < n) {

    int r = l;
    while (r < n && !Query(v[r], v[last])) {
      r++;
    }
    assert(r < n);
    last = l;
    for (int j = r; j >= l; j--) {
      rl.push_back(v[j]);
    }
    l = r + 1;
  }
  vector<int> inv(n);
  for (int i = 0; i < n; i++) {
    inv[rl[i]] = i;
  }
  return inv;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 200 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 200 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 92 ms 284 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -