답안 #940661

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940661 2024-03-07T12:48:44 Z Sundavar Monster Game (JOI21_monster) C++17
0 / 100
56 ms 4440 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> solve(vector<int> v){
  int N = v.size();
  if(N <= 12){
    vector<pair<int,int> > cnt(N);
    vector<int> amb1, amb2;
    for(int i = 0; i < N; i++){
      cnt[i].second = v[i];
      for(int j = 0; j < i; j++)
        if(j != i){
          if(ask(v[i],v[j])) cnt[i].first++;
          else cnt[j].first++;
        }
    }
    sort(cnt.begin(), cnt.end());
    if(cnt[0].first == cnt[1].first){
      if(!ask(cnt[0].second,cnt[1].second)) swap(cnt[0], cnt[1]);
    }
    if(cnt[1].first == cnt[2].first){
      if(!ask(cnt[1].second,cnt[2].second)) swap(cnt[1], cnt[2]);
    }
    if(cnt[N-2].first == cnt[N-1].first){
      if(!ask(cnt[N-2].second,cnt[N-1].second)) swap(cnt[N-2], cnt[N-1]);
    }
    if(cnt[N-3].first == cnt[N-2].first){
      if(!ask(cnt[N-3].second,cnt[N-2].second)) swap(cnt[N-3], cnt[N-2]);
    }
    vector<int> res;
    for(pair<int,int>& a : cnt) res.push_back(a.second);
    return res;
  }
  vector<int> left, right;
  int m = rng()%N;
  while(true){
    left.clear(), right.clear();
    for(int i = 0; i < N; i++)
      if(i != m){
        if(ask(v[m], v[i])) left.push_back(v[i]);
        else right.push_back(v[i]);
      }
    if(min(left.size(), right.size()) <= 5){
      m = rng()%N;
      continue;
    }
    break;
  }
  left = solve(left), right = solve(right);
  if(!ask(left[left.size()-1], v[m])) swap(left[left.size()-1], right[0]);
  vector<int> res;
  for(int& a : left) res.push_back(a);
  res.push_back(v[m]);
  for(int& a : right) res.push_back(a);
  return res;
}

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 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 i = 0; 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;
    }
  }
  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:73:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   for(int i = 0; i < v.size(); i++)
      |                  ~~^~~~~~~~~~
monster.cpp:74:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     if(i < v.size()/2) left.push_back(v[i]);
      |        ~~^~~~~~~~~~~~
monster.cpp:79:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |   for(int l = 0, r = 0; l < left.size() || r < right.size();){
      |                         ~~^~~~~~~~~~~~~
monster.cpp:79:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |   for(int l = 0, r = 0; l < left.size() || r < right.size();){
      |                                            ~~^~~~~~~~~~~~~~
monster.cpp:80:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     if(r == right.size() || (l < left.size() && ask(right[r], left[l]))) res.push_back(left[l++]);
      |        ~~^~~~~~~~~~~~~~~
monster.cpp:80:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     if(r == right.size() || (l < left.size() && ask(right[r], left[l]))) res.push_back(left[l++]);
      |                              ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4180 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4180 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 56 ms 4440 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -