답안 #1061025

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

namespace {

bool example_variable;

} // namespace

const int maxn = 1000;
vector<vector<int>> vvi(maxn,vector<int>(maxn,-1));

bool Qry(int a,int b)
{
  if(vvi[a][b] == -1)
  {
    vvi[a][b] = Query(a,b);
    vvi[b][a] = 1 - vvi[a][b];
  }
  return vvi[a][b];
}

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 (Qry(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 (Qry(ovi[i], ovi[j])) {
          winct++;
          if (winct == 2) {
            break;
          }
        }
      }
    }
    if (winct < 2) {
      vpii.push_back(i);
    }
  }

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

  int curr;
  if (Qry(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 (Qry(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:40:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     while (in1 < vi2.size() && in2 < vi3.size()) {
      |            ~~~~^~~~~~~~~~~~
monster.cpp:40:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     while (in1 < vi2.size() && in2 < vi3.size()) {
      |                                ~~~~^~~~~~~~~~~~
monster.cpp:50:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     while (in1 < vi2.size()) {
      |            ~~~~^~~~~~~~~~~~
monster.cpp:55:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     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:112:23: warning: 'curl' may be used uninitialized in this function [-Wmaybe-uninitialized]
  112 |       if (Qry(ovi[curl], ovi[i])) {
      |                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4184 KB Output is correct
3 Correct 2 ms 4184 KB Output is correct
4 Correct 2 ms 4184 KB Output is correct
5 Correct 2 ms 4184 KB Output is correct
6 Correct 2 ms 4184 KB Output is correct
7 Correct 2 ms 4184 KB Output is correct
8 Correct 2 ms 4184 KB Output is correct
9 Correct 2 ms 4184 KB Output is correct
10 Correct 2 ms 4184 KB Output is correct
11 Correct 2 ms 4184 KB Output is correct
12 Correct 2 ms 4184 KB Output is correct
13 Correct 3 ms 4184 KB Output is correct
14 Correct 2 ms 4184 KB Output is correct
15 Correct 2 ms 4184 KB Output is correct
16 Correct 11 ms 4184 KB Output is correct
17 Correct 12 ms 4396 KB Output is correct
18 Correct 12 ms 4184 KB Output is correct
19 Correct 10 ms 4168 KB Output is correct
20 Correct 11 ms 4184 KB Output is correct
21 Correct 2 ms 4184 KB Output is correct
22 Correct 2 ms 4176 KB Output is correct
23 Correct 2 ms 4184 KB Output is correct
24 Correct 2 ms 4184 KB Output is correct
25 Correct 2 ms 4184 KB Output is correct
26 Correct 6 ms 4184 KB Output is correct
27 Correct 2 ms 4184 KB Output is correct
28 Correct 2 ms 4184 KB Output is correct
29 Correct 2 ms 4184 KB Output is correct
30 Correct 2 ms 4328 KB Output is correct
31 Correct 2 ms 4184 KB Output is correct
32 Correct 8 ms 4184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4184 KB Output is correct
3 Correct 2 ms 4184 KB Output is correct
4 Correct 2 ms 4184 KB Output is correct
5 Correct 2 ms 4184 KB Output is correct
6 Correct 2 ms 4184 KB Output is correct
7 Correct 2 ms 4184 KB Output is correct
8 Correct 2 ms 4184 KB Output is correct
9 Correct 2 ms 4184 KB Output is correct
10 Correct 2 ms 4184 KB Output is correct
11 Correct 2 ms 4184 KB Output is correct
12 Correct 2 ms 4184 KB Output is correct
13 Correct 3 ms 4184 KB Output is correct
14 Correct 2 ms 4184 KB Output is correct
15 Correct 2 ms 4184 KB Output is correct
16 Correct 11 ms 4184 KB Output is correct
17 Correct 12 ms 4396 KB Output is correct
18 Correct 12 ms 4184 KB Output is correct
19 Correct 10 ms 4168 KB Output is correct
20 Correct 11 ms 4184 KB Output is correct
21 Correct 2 ms 4184 KB Output is correct
22 Correct 2 ms 4176 KB Output is correct
23 Correct 2 ms 4184 KB Output is correct
24 Correct 2 ms 4184 KB Output is correct
25 Correct 2 ms 4184 KB Output is correct
26 Correct 6 ms 4184 KB Output is correct
27 Correct 2 ms 4184 KB Output is correct
28 Correct 2 ms 4184 KB Output is correct
29 Correct 2 ms 4184 KB Output is correct
30 Correct 2 ms 4328 KB Output is correct
31 Correct 2 ms 4184 KB Output is correct
32 Correct 8 ms 4184 KB Output is correct
33 Correct 61 ms 4440 KB Output is correct
34 Correct 59 ms 4184 KB Output is correct
35 Correct 68 ms 4184 KB Output is correct
36 Correct 61 ms 4388 KB Output is correct
37 Correct 56 ms 4440 KB Output is correct
38 Correct 60 ms 4184 KB Output is correct
39 Correct 74 ms 4428 KB Output is correct
40 Correct 71 ms 4184 KB Output is correct
41 Correct 76 ms 4432 KB Output is correct
42 Correct 53 ms 4392 KB Output is correct
43 Correct 38 ms 4688 KB Output is correct
44 Correct 53 ms 4692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 55 ms 4396 KB Partially correct
2 Partially correct 71 ms 4436 KB Partially correct
3 Partially correct 59 ms 4184 KB Partially correct
4 Partially correct 59 ms 4380 KB Partially correct
5 Partially correct 56 ms 4632 KB Partially correct
6 Correct 43 ms 4432 KB Output is correct
7 Correct 57 ms 4184 KB Output is correct
8 Partially correct 55 ms 4440 KB Partially correct
9 Partially correct 64 ms 4388 KB Partially correct
10 Partially correct 73 ms 4636 KB Partially correct
11 Partially correct 67 ms 4428 KB Partially correct
12 Partially correct 81 ms 4392 KB Partially correct
13 Correct 49 ms 4184 KB Output is correct
14 Correct 53 ms 4432 KB Output is correct
15 Correct 43 ms 4432 KB Output is correct
16 Correct 45 ms 4432 KB Output is correct
17 Partially correct 76 ms 4380 KB Partially correct
18 Correct 52 ms 4388 KB Output is correct