Submission #1353484

#TimeUsernameProblemLanguageResultExecution timeMemory
1353484vyaductMonster Game (JOI21_monster)C++20
0 / 100
43 ms4164 KiB
#include "monster.h"
#include <bits/stdc++.h>
using namespace std;

#define all(c) (c).begin(), (c).end()

/*
  if |S[a]-S[b]| = 1: returns S[a] < S[b]
  else returns S[a] > S[b]

  Choose a > b by default:
  returns a winning if 
  (S[a] > S[b] or S[b] == S[a]+1) and S[b] != S[a]-1
*/

vector<int> Solve(int N) {
  vector<vector<int>> res(N, vector<int>(N, 0));
  vector<int> T(N, -1);
  for (int a=0;a<N;a++){
    for (int b=0;b<a;b++){
      res[a][b] = Query(a, b);
      res[b][a] = 1 - res[a][b];
    }
  }
  pair<int, int> top = {-1, -1};
  pair<int, int> bot = {-1, -1};
  for (int a=0;a<N;a++){
    int cnt = accumulate(all(res[a]), 0);
    if (cnt == N-2){
      if (top.first == -1) top.first = a;
      else if (top.second == -1) top.second = a;
      else assert(false && "le caca");
    } else if (cnt == 1){
      if (bot.first == -1) bot.first = a;
      else if (bot.second == -1) bot.second = a;
      else assert(false && "le caca");
    } else T[a]=cnt;
  }

  if (top.first > top.second) swap(top.first, top.second);
  if (res[top.first][top.second]) T[top.first] = N-2, T[top.second] = N-1;
  else T[top.first] = N-2, T[top.second] = N-1;

  if (bot.first > bot.second) swap(bot.first, bot.second);
  if (res[bot.first][bot.second]) T[bot.first] = 0, T[bot.second] = 1;
  else T[bot.first] = 1, T[bot.second] = 0;

  // for (int x: T) { cout << x << " "; } cout << endl;
  return T;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...