Submission #940698

# Submission time Handle Problem Language Result Execution time Memory
940698 2024-03-07T13:39:30 Z Sundavar Monster Game (JOI21_monster) C++17
0 / 100
56 ms 4404 KB
#include "monster.h"
#include <bits/stdc++.h>
using namespace std;

mt19937 rng(45345345);

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;
}

std::vector<int> Solve(int N) {
  vector<int> v;
  for(int i = 0; i < N ; i++) v.push_back(i);
  v = solve2(v);
  /*for(int& a : v) cout<<a<<" ";
  cout << "\n";*/
  
  int cnt = 0, j = 0;
  for(int i = 1; i < N; i++) cnt += ask(v[0], v[i]);
  if(cnt == 1){
    if(ask(v[0], v[1])) j = 2;
    else{
      int cnt2 = 0;
      for(int i = 0; i < N; i++) if(i != 1) cnt2 += ask(v[1], v[i]);
      if(cnt2 != 1) j = 1;
      else swap(v[0], v[1]), j = 2;
    }
  }
  for(int i = j; i < N; i++){
    if(!ask(v[i], v[i+1])){
      int l = 1;
      while(i+l+1 < N && ask(v[i], v[i+l+1])) l++;
      for(int j = 0; j < (l+1)/2; j++) swap(v[i], v[i+l-j]);
      i += l;
    }
  }
  /*for(int& a : v) cout<<a<<" ";
  cout << "\n";*/
  vector<int> T(N);
  for(int i = 0; i < N; i++) T[v[i]] = i;
  /*for(int& a : T) cout<<a<<" ";
  cout << "\n";*/
  return T;
}

Compilation message

monster.cpp: In function 'std::vector<int> solve2(std::vector<int>)':
monster.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |   for(int i = 0; i < v.size(); i++)
      |                  ~~^~~~~~~~~~
monster.cpp:20:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     if(i < v.size()/2) left.push_back(v[i]);
      |        ~~^~~~~~~~~~~~
monster.cpp:29:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for(int l = 0, r = 0; l < left.size() || r < right.size();){
      |                         ~~^~~~~~~~~~~~~
monster.cpp:29:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for(int l = 0, r = 0; l < left.size() || r < right.size();){
      |                                            ~~^~~~~~~~~~~~~~
monster.cpp:30:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     if(r == right.size() || (l < left.size() && ask(right[r], left[l]))) res.push_back(left[l++]);
      |        ~~^~~~~~~~~~~~~~~
monster.cpp:30:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     if(r == right.size() || (l < left.size() && ask(right[r], left[l]))) res.push_back(left[l++]);
      |                              ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4184 KB Output is correct
2 Correct 2 ms 4288 KB Output is correct
3 Correct 2 ms 4184 KB Output is correct
4 Correct 2 ms 4184 KB Output is correct
5 Incorrect 2 ms 4184 KB Wrong Answer [3]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4184 KB Output is correct
2 Correct 2 ms 4288 KB Output is correct
3 Correct 2 ms 4184 KB Output is correct
4 Correct 2 ms 4184 KB Output is correct
5 Incorrect 2 ms 4184 KB Wrong Answer [3]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 4404 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -