답안 #940762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940762 2024-03-07T15:20:39 Z Sundavar Monster Game (JOI21_monster) C++17
100 / 100
71 ms 4912 KB
#include "monster.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(11);

vector<vector<int> > m(1000, vector<int>(1000, -1));
bool ask(int a, int b){
  if(m[a][b] == -1){
    m[a][b] = Query(a,b);
    m[b][a] = 1 - m[a][b];
  }
  return m[a][b];
}

vector<int> solve2(vector<int> v){
  if(v.size() == 1) return v;
  vector<int> left, right;
  for(int i = 0; i < v.size(); i++)
    if(i < v.size()/2) left.push_back(v[i]);
    else right.push_back(v[i]);
  left = solve2(left), right = solve2(right);
  vector<int> res;
  /*for(int& a : left) cout << a << " ";
  cout << "\n";
  for(int& a : right) cout << a << " ";
  cout << "\n";
  cout << "\n";*/
  for(int l = 0, r = 0; l < left.size() || r < right.size();){
    if(r == right.size() || (l < left.size() && ask(right[r], left[l]))) res.push_back(left[l++]);
    else res.push_back(right[r++]);
  }
  return res;
}

void correct_long(vector<int>& v, int i){
  int l = 1;
  while(i+l+1 < v.size() && ask(v[i], v[i+l+1])) l++;
  for(int j = 0; j < (l+1)/2; j++) swap(v[i+j], v[i+l-j]);
}

void correct_v(vector<int>& v, int i){
  int l = 1;
  while(i+l < v.size() && !ask(v[i-1], v[i+l])) l++;
  for(int j = 0; j < (l+1)/2; j++) swap(v[i+j], v[i+l-j]);
}

std::vector<int> Solve(int N) {
  vector<int> v;
  for(int i = 0; i < N ; i++) v.push_back(i);
  shuffle(v.begin(), v.end(), rng);
  v = solve2(v);
  /*for(int& a : v) cout<<a<<" ";
  cout << "\n";*/
  
  int cnt = 0, j = 0;
  int x = min(N, 10);
  for(int i = 1; i < x; i++){
    cnt += ask(v[0], v[i]);
    if(cnt > 1) break;
  }
  if(cnt != 1){
    correct_long(v, 0);
  }
  if(cnt == 1 && !ask(v[0], v[1])){
    int cnt2 = 0;
    for(int i = 0; i < x; i++) if(i != 1){
      cnt2 += ask(v[1], v[i]);
      if(cnt2 > 1) break;
    }
    if(cnt2 == 1) swap(v[0], v[1]);
  }
  for(int i = 0; i < N-1; i++){
    if(!ask(v[i], v[i+1])){ 
      correct_v(v, i+1);
      /*for(int& a : v) cout<<a<<" ";
      cout << "\n";*/
    }
  }
  /*for(int& a : v) cout<<a<<" ";
  cout << "\n";*/
  vector<int> T(N);
  for(int i = 0; i < N; i++) T[v[i]] = i;
  return T;
}

Compilation message

monster.cpp: In function 'std::vector<int> solve2(std::vector<int>)':
monster.cpp:18:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   for(int i = 0; i < v.size(); i++)
      |                  ~~^~~~~~~~~~
monster.cpp:19:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     if(i < v.size()/2) left.push_back(v[i]);
      |        ~~^~~~~~~~~~~~
monster.cpp:28:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   for(int l = 0, r = 0; l < left.size() || r < right.size();){
      |                         ~~^~~~~~~~~~~~~
monster.cpp:28:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   for(int l = 0, r = 0; l < left.size() || r < right.size();){
      |                                            ~~^~~~~~~~~~~~~~
monster.cpp:29:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     if(r == right.size() || (l < left.size() && ask(right[r], left[l]))) res.push_back(left[l++]);
      |        ~~^~~~~~~~~~~~~~~
monster.cpp:29:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     if(r == right.size() || (l < left.size() && ask(right[r], left[l]))) res.push_back(left[l++]);
      |                              ~~^~~~~~~~~~~~~
monster.cpp: In function 'void correct_long(std::vector<int>&, int)':
monster.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   while(i+l+1 < v.size() && ask(v[i], v[i+l+1])) l++;
      |         ~~~~~~^~~~~~~~~~
monster.cpp: In function 'void correct_v(std::vector<int>&, int)':
monster.cpp:43:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   while(i+l < v.size() && !ask(v[i-1], v[i+l])) l++;
      |         ~~~~^~~~~~~~~~
monster.cpp: In function 'std::vector<int> Solve(int)':
monster.cpp:55:16: warning: unused variable 'j' [-Wunused-variable]
   55 |   int cnt = 0, j = 0;
      |                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4184 KB Output is correct
2 Correct 2 ms 4184 KB Output is correct
3 Correct 3 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 2 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 8 ms 4184 KB Output is correct
17 Correct 7 ms 4184 KB Output is correct
18 Correct 7 ms 4184 KB Output is correct
19 Correct 7 ms 4184 KB Output is correct
20 Correct 7 ms 4184 KB Output is correct
21 Correct 2 ms 4184 KB Output is correct
22 Correct 2 ms 4184 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 8 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 4436 KB Output is correct
30 Correct 2 ms 4184 KB Output is correct
31 Correct 2 ms 4184 KB Output is correct
32 Correct 7 ms 4184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4184 KB Output is correct
2 Correct 2 ms 4184 KB Output is correct
3 Correct 3 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 2 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 8 ms 4184 KB Output is correct
17 Correct 7 ms 4184 KB Output is correct
18 Correct 7 ms 4184 KB Output is correct
19 Correct 7 ms 4184 KB Output is correct
20 Correct 7 ms 4184 KB Output is correct
21 Correct 2 ms 4184 KB Output is correct
22 Correct 2 ms 4184 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 8 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 4436 KB Output is correct
30 Correct 2 ms 4184 KB Output is correct
31 Correct 2 ms 4184 KB Output is correct
32 Correct 7 ms 4184 KB Output is correct
33 Correct 38 ms 4656 KB Output is correct
34 Correct 49 ms 4688 KB Output is correct
35 Correct 49 ms 4440 KB Output is correct
36 Correct 40 ms 4904 KB Output is correct
37 Correct 39 ms 4912 KB Output is correct
38 Correct 47 ms 4656 KB Output is correct
39 Correct 40 ms 4436 KB Output is correct
40 Correct 48 ms 4436 KB Output is correct
41 Correct 50 ms 4688 KB Output is correct
42 Correct 42 ms 4672 KB Output is correct
43 Correct 40 ms 4416 KB Output is correct
44 Correct 39 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 4420 KB Output is correct
2 Correct 40 ms 4440 KB Output is correct
3 Correct 40 ms 4416 KB Output is correct
4 Correct 48 ms 4440 KB Output is correct
5 Correct 43 ms 4664 KB Output is correct
6 Correct 32 ms 4432 KB Output is correct
7 Correct 32 ms 4688 KB Output is correct
8 Correct 71 ms 4440 KB Output is correct
9 Correct 42 ms 4664 KB Output is correct
10 Correct 51 ms 4900 KB Output is correct
11 Correct 44 ms 4440 KB Output is correct
12 Correct 43 ms 4692 KB Output is correct
13 Correct 44 ms 4396 KB Output is correct
14 Correct 41 ms 4696 KB Output is correct
15 Correct 26 ms 4416 KB Output is correct
16 Correct 24 ms 4416 KB Output is correct
17 Correct 34 ms 4656 KB Output is correct
18 Correct 24 ms 4688 KB Output is correct