답안 #493593

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493593 2021-12-12T09:57:14 Z 600Mihnea Monster Game (JOI21_monster) C++17
100 / 100
127 ms 532 KB
#include <bits/stdc++.h>
#include "monster.h"

using namespace std;

bool qq(int a, int b) {
  return Query(b, a);
}

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 (qq(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] += !qq(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 (!qq(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 && !qq(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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 0 ms 200 KB Output is correct
6 Correct 0 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Correct 2 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 1 ms 200 KB Output is correct
16 Correct 15 ms 200 KB Output is correct
17 Correct 13 ms 268 KB Output is correct
18 Correct 19 ms 200 KB Output is correct
19 Correct 14 ms 200 KB Output is correct
20 Correct 15 ms 200 KB Output is correct
21 Correct 1 ms 200 KB Output is correct
22 Correct 1 ms 200 KB Output is correct
23 Correct 1 ms 200 KB Output is correct
24 Correct 1 ms 200 KB Output is correct
25 Correct 1 ms 200 KB Output is correct
26 Correct 12 ms 288 KB Output is correct
27 Correct 2 ms 200 KB Output is correct
28 Correct 1 ms 200 KB Output is correct
29 Correct 1 ms 200 KB Output is correct
30 Correct 2 ms 200 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 12 ms 292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 0 ms 200 KB Output is correct
6 Correct 0 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Correct 2 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 1 ms 200 KB Output is correct
16 Correct 15 ms 200 KB Output is correct
17 Correct 13 ms 268 KB Output is correct
18 Correct 19 ms 200 KB Output is correct
19 Correct 14 ms 200 KB Output is correct
20 Correct 15 ms 200 KB Output is correct
21 Correct 1 ms 200 KB Output is correct
22 Correct 1 ms 200 KB Output is correct
23 Correct 1 ms 200 KB Output is correct
24 Correct 1 ms 200 KB Output is correct
25 Correct 1 ms 200 KB Output is correct
26 Correct 12 ms 288 KB Output is correct
27 Correct 2 ms 200 KB Output is correct
28 Correct 1 ms 200 KB Output is correct
29 Correct 1 ms 200 KB Output is correct
30 Correct 2 ms 200 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 12 ms 292 KB Output is correct
33 Correct 59 ms 296 KB Output is correct
34 Correct 97 ms 296 KB Output is correct
35 Correct 59 ms 292 KB Output is correct
36 Correct 84 ms 288 KB Output is correct
37 Correct 93 ms 284 KB Output is correct
38 Correct 95 ms 408 KB Output is correct
39 Correct 44 ms 324 KB Output is correct
40 Correct 127 ms 280 KB Output is correct
41 Correct 80 ms 284 KB Output is correct
42 Correct 82 ms 280 KB Output is correct
43 Correct 69 ms 288 KB Output is correct
44 Correct 65 ms 288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 320 KB Output is correct
2 Correct 87 ms 296 KB Output is correct
3 Correct 77 ms 200 KB Output is correct
4 Correct 70 ms 292 KB Output is correct
5 Correct 106 ms 284 KB Output is correct
6 Correct 69 ms 280 KB Output is correct
7 Correct 89 ms 284 KB Output is correct
8 Correct 60 ms 448 KB Output is correct
9 Correct 91 ms 284 KB Output is correct
10 Correct 95 ms 280 KB Output is correct
11 Correct 69 ms 284 KB Output is correct
12 Correct 118 ms 532 KB Output is correct
13 Correct 95 ms 280 KB Output is correct
14 Correct 70 ms 408 KB Output is correct
15 Correct 55 ms 284 KB Output is correct
16 Correct 48 ms 288 KB Output is correct
17 Correct 65 ms 200 KB Output is correct
18 Correct 56 ms 400 KB Output is correct