답안 #1061011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1061011 2024-08-16T05:33:50 Z kunzaZa183 Monster Game (JOI21_monster) C++17
81 / 100
88 ms 848 KB
#include "monster.h"
#include <bits/stdc++.h>
#include <cassert>
using namespace std;

namespace {

bool example_variable;

} // namespace

vector<int> Solve(int N) {
  vector<int> vi(N);
  vi.resize(N);
  iota(vi.begin(), vi.end(), 0);

  function<vector<int>(int, int)> merge = [&](int l, int r) {
    if (l == r) {
      return vector<int>(1, vi[l]);
    }
    vector<int> vi;

    int mid = (l + r) / 2;
    vector<int> vi2 = merge(l, mid), vi3 = merge(mid + 1, r);

    int in1 = 0, in2 = 0;
    while (in1 < vi2.size() && in2 < vi3.size()) {
      if (Query(vi2[in1], vi3[in2])) {
        vi.push_back(vi3[in2]);
        in2++;
      } else {
        vi.push_back(vi2[in1]);
        in1++;
      }
    }

    while (in1 < vi2.size()) {
      vi.push_back(vi2[in1]);
      in1++;
    }

    while (in2 < vi3.size()) {
      vi.push_back(vi3[in2]);
      in2++;
    }

    return vi;
  };

  vector<int> ovi = merge(0, N - 1);

  // for (auto a : ovi)
  //   cout << a << " ";
  // cout << "\n";

  vector<int> vpii;

  for (int i = 0; i < N; i++) {
    int winct = 0;
    for (int j = 0; j < N; j++) {
      if (i != j) {
        if (Query(ovi[i], ovi[j])) {
          winct++;
          if (winct == 2) {
            break;
          }
        }
      }
    }
    if (winct < 2) {
      vpii.push_back(i);
    }
  }

  assert(vpii.size() == 2);

  int curr;
  if (Query(ovi[vpii[0]], ovi[vpii[1]])) {
    curr = vpii[0];
  } else {
    curr = vpii[1];
  }
  // cout << ovi[curr] << "\n";

  vector<int> orans(N, -1);

  int curval = 0, curl;
  while (1) {
    for (int i = curr; i >= 0; i--) {
      if (orans[i] != -1)
        break;
      orans[i] = curval++;
      curl = i;
    }

    for (int i = curr + 1; 1; i++) {
      if (i == N)
        goto A;
      if (Query(ovi[curl], ovi[i])) {
        curr = i;
        break;
      }
    }
  }
A:;

  vector<int> ans(N);
  for (int i = 0; i < N; i++)
    ans[ovi[i]] = orans[i];

  return ans;
}

Compilation message

monster.cpp: In lambda function:
monster.cpp:27:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     while (in1 < vi2.size() && in2 < vi3.size()) {
      |            ~~~~^~~~~~~~~~~~
monster.cpp:27:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     while (in1 < vi2.size() && in2 < vi3.size()) {
      |                                ~~~~^~~~~~~~~~~~
monster.cpp:37:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     while (in1 < vi2.size()) {
      |            ~~~~^~~~~~~~~~~~
monster.cpp:42:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     while (in2 < vi3.size()) {
      |            ~~~~^~~~~~~~~~~~
monster.cpp: At global scope:
monster.cpp:8:6: warning: '{anonymous}::example_variable' defined but not used [-Wunused-variable]
    8 | bool example_variable;
      |      ^~~~~~~~~~~~~~~~
monster.cpp: In function 'std::vector<int> Solve(int)':
monster.cpp:99:25: warning: 'curl' may be used uninitialized in this function [-Wmaybe-uninitialized]
   99 |       if (Query(ovi[curl], ovi[i])) {
      |                         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 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 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 352 KB Output is correct
16 Correct 10 ms 344 KB Output is correct
17 Correct 13 ms 352 KB Output is correct
18 Correct 10 ms 440 KB Output is correct
19 Correct 10 ms 600 KB Output is correct
20 Correct 10 ms 444 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 7 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 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 9 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 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 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 352 KB Output is correct
16 Correct 10 ms 344 KB Output is correct
17 Correct 13 ms 352 KB Output is correct
18 Correct 10 ms 440 KB Output is correct
19 Correct 10 ms 600 KB Output is correct
20 Correct 10 ms 444 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 7 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 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 9 ms 452 KB Output is correct
33 Correct 67 ms 684 KB Output is correct
34 Correct 88 ms 432 KB Output is correct
35 Correct 69 ms 684 KB Output is correct
36 Correct 66 ms 680 KB Output is correct
37 Correct 65 ms 444 KB Output is correct
38 Correct 65 ms 592 KB Output is correct
39 Correct 69 ms 424 KB Output is correct
40 Correct 60 ms 420 KB Output is correct
41 Correct 69 ms 592 KB Output is correct
42 Correct 62 ms 600 KB Output is correct
43 Correct 51 ms 672 KB Output is correct
44 Correct 53 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 67 ms 596 KB Partially correct
2 Partially correct 80 ms 604 KB Partially correct
3 Partially correct 54 ms 592 KB Partially correct
4 Partially correct 73 ms 436 KB Partially correct
5 Partially correct 67 ms 676 KB Partially correct
6 Partially correct 43 ms 596 KB Partially correct
7 Partially correct 61 ms 420 KB Partially correct
8 Partially correct 78 ms 848 KB Partially correct
9 Partially correct 78 ms 600 KB Partially correct
10 Partially correct 72 ms 432 KB Partially correct
11 Partially correct 80 ms 416 KB Partially correct
12 Partially correct 74 ms 676 KB Partially correct
13 Partially correct 72 ms 420 KB Partially correct
14 Partially correct 64 ms 344 KB Partially correct
15 Partially correct 57 ms 696 KB Partially correct
16 Correct 63 ms 440 KB Output is correct
17 Partially correct 69 ms 420 KB Partially correct
18 Correct 56 ms 684 KB Output is correct