답안 #894065

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894065 2023-12-27T23:31:39 Z MilosMilutinovic Monster Game (JOI21_monster) C++17
91 / 100
60 ms 1364 KB
#include "monster.h"
#include <bits/stdc++.h>

using namespace std;

namespace {

bool example_variable;

}  // namespace

vector<int> Solve(int n) {
  vector<int> order(n);
  iota(order.begin(), order.end(), 0);
  vector<int> tmp(n);
  function<void(int, int)> MergeSort = [&](int l, int r) {
    if (l == r) {
      return;
    }
    int mid = l + r >> 1;
    MergeSort(l, mid);
    MergeSort(mid + 1, r);
    for (int i = l; i <= r; i++) {
      tmp[i] = order[i];
    }
    int pl = l, pr = mid + 1;
    int ptr = l;
    while (pl <= mid || pr <= r) {
      if (pl > mid) {
        order[ptr++] = tmp[pr++];
      } else if (pr > r) {
        order[ptr++] = tmp[pl++];
      } else {
        order[ptr++] = (Query(tmp[pl], tmp[pr]) ? tmp[pl++] : tmp[pr++]);
      }
    }
  };
  MergeSort(0, n - 1);
  int pos = -1;
  vector<int> bad;
  for (int i = 1; i < n; i++) {
    if (!Query(order[0], order[i])) {
      bad.push_back(i);
    }
  }
  if ((int) bad.size() > 1) {
    pos = bad.rbegin()[1];
  } else {
    bool ok = true;
    for (int i = 2; i < n; i++) {
      if (!Query(order[1], order[i])) {
        ok = false;
        break;
      }
    }
    if (ok) {
      pos = 1;
    } else {
      pos = 0;
    }
  }
  vector<int> res;
  function<void(int, int)> Solve = [&](int l, int r) {
    for (int i = r; i >= l; i--) {
      res.push_back(order[i]);
    }
    if (r == n - 1) {
      return;
    }
    for (int i = r + 1; i < n; i++) {
      if (!Query(order[l], order[i])) {
        Solve(r + 1, i);
        break;
      }
    }
  };
  Solve(0, pos);
  reverse(res.begin(), res.end());
  vector<int> ret(n);
  for (int i = 0; i < n; i++) {
    ret[res[i]] = i;
  }
  return ret;
}

Compilation message

monster.cpp: In lambda function:
monster.cpp:20:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |     int mid = l + r >> 1;
      |               ~~^~~
monster.cpp: At global scope:
monster.cpp:8:6: warning: '{anonymous}::example_variable' defined but not used [-Wunused-variable]
    8 | bool example_variable;
      |      ^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 7 ms 344 KB Output is correct
17 Correct 7 ms 600 KB Output is correct
18 Correct 6 ms 600 KB Output is correct
19 Correct 7 ms 600 KB Output is correct
20 Correct 7 ms 600 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 368 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 4 ms 440 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 5 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 7 ms 344 KB Output is correct
17 Correct 7 ms 600 KB Output is correct
18 Correct 6 ms 600 KB Output is correct
19 Correct 7 ms 600 KB Output is correct
20 Correct 7 ms 600 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 368 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 4 ms 440 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 5 ms 600 KB Output is correct
33 Correct 37 ms 420 KB Output is correct
34 Correct 46 ms 592 KB Output is correct
35 Correct 46 ms 928 KB Output is correct
36 Correct 60 ms 592 KB Output is correct
37 Correct 48 ms 676 KB Output is correct
38 Correct 43 ms 432 KB Output is correct
39 Correct 47 ms 676 KB Output is correct
40 Correct 40 ms 684 KB Output is correct
41 Correct 48 ms 932 KB Output is correct
42 Correct 39 ms 436 KB Output is correct
43 Correct 28 ms 692 KB Output is correct
44 Correct 34 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 42 ms 420 KB Partially correct
2 Partially correct 45 ms 424 KB Partially correct
3 Partially correct 48 ms 680 KB Partially correct
4 Partially correct 44 ms 596 KB Partially correct
5 Partially correct 38 ms 680 KB Partially correct
6 Partially correct 37 ms 848 KB Partially correct
7 Partially correct 43 ms 444 KB Partially correct
8 Partially correct 47 ms 452 KB Partially correct
9 Partially correct 48 ms 1364 KB Partially correct
10 Partially correct 50 ms 424 KB Partially correct
11 Partially correct 49 ms 680 KB Partially correct
12 Partially correct 41 ms 1184 KB Partially correct
13 Partially correct 43 ms 676 KB Partially correct
14 Partially correct 36 ms 432 KB Partially correct
15 Correct 23 ms 592 KB Output is correct
16 Correct 33 ms 592 KB Output is correct
17 Correct 36 ms 416 KB Output is correct
18 Correct 41 ms 672 KB Output is correct