Submission #795799

# Submission time Handle Problem Language Result Execution time Memory
795799 2023-07-27T15:38:56 Z peijar Monster Game (JOI21_monster) C++17
0 / 100
72 ms 448 KB
#include "monster.h"
#include <bits/stdc++.h>
using namespace std;

// a beaten by b
bool comp(int a, int b) { return Query(b, a); }

vector<int> merge_sort(vector<int> vec) {
  if (vec.size() == 1)
    return vec;
  vector<int> l, r;
  for (int i = 0; i < (int)vec.size(); ++i) {
    if (i % 2)
      r.push_back(vec[i]);
    else
      l.push_back(vec[i]);
  }
  l = merge_sort(l);
  r = merge_sort(r);
  merge(l.begin(), l.end(), r.begin(), r.end(), vec.begin(), comp);
  return vec;
}

vector<int> Solve(int N) {
  vector<int> sorted(N);
  iota(sorted.begin(), sorted.end(), 0LL);
  sorted = merge_sort(sorted);

  vector<int> debut;
  for (int i = 0; i < min(N, 10); ++i)
    debut.push_back(sorted[i]);

  int nbDebut = debut.size();
  vector<int> cntWins(nbDebut);

  for (int i = 0; i < nbDebut; ++i)
    for (int j = i + 1; j < nbDebut; ++j) {
      if (comp(i, j))
        cntWins[j]++;
      else
        cntWins[i]++;
    }

  int valMin = *min_element(cntWins.begin(), cntWins.end());

  vector<int> withVal;
  for (int i = 0; i < nbDebut; ++i)
    if (cntWins[i] == valMin)
      withVal.push_back(i);
  assert(withVal.size() == 2);
  int posMin = comp(withVal[0], withVal[1]) ? withVal[1] : withVal[0];
  vector<int> newSorted;
  newSorted.push_back(posMin);
  for (int x : sorted)
    if (x != posMin)
      newSorted.push_back(x);

  sorted = move(newSorted);

  for (int deb = 1; deb < N;) {
    int fin = deb;
    while (comp(sorted[deb - 1], sorted[fin]))
      ++fin;
    reverse(sorted.begin() + deb, sorted.begin() + fin + 1);
    deb = fin + 1;
  }

  vector<int> T(N);
  for (int i = 0; i < N; i++)
    T[sorted[i]] = i;

  return T;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 276 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Runtime error 11 ms 432 KB Execution killed with signal 6
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 276 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Runtime error 11 ms 432 KB Execution killed with signal 6
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 72 ms 448 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -