Submission #795808

# Submission time Handle Problem Language Result Execution time Memory
795808 2023-07-27T15:50:14 Z peijar Monster Game (JOI21_monster) C++17
100 / 100
82 ms 304 KB
#include "monster.h"
#include <bits/stdc++.h>
using namespace std;

string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
  bool first = true;
  string res = "[";
  for (const auto &x : v) {
    if (!first)
      res += ", ";
    first = false;
    res += to_string(x);
  }
  res += "]";
  return res;
}

void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
  cout << ' ' << to_string(H);
  dbg_out(T...);
}

#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

// 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> S = {13, 11, 12, 0, 3, 6, 1, 5, 7, 8, 4, 10, 2, 14, 9};

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

  dbg(sorted);

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

  int nbDebut = debut.size();
  // for (int i = 0; i < nbDebut; ++i)
  // dbg(S[debut[i]]);
  vector<int> cntWins(nbDebut);

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

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

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

  dbg(posMin);
  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 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 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 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 11 ms 280 KB Output is correct
17 Correct 7 ms 296 KB Output is correct
18 Correct 10 ms 208 KB Output is correct
19 Correct 11 ms 300 KB Output is correct
20 Correct 10 ms 208 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 0 ms 208 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 6 ms 208 KB Output is correct
27 Correct 0 ms 208 KB Output is correct
28 Correct 0 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 14 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 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 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 11 ms 280 KB Output is correct
17 Correct 7 ms 296 KB Output is correct
18 Correct 10 ms 208 KB Output is correct
19 Correct 11 ms 300 KB Output is correct
20 Correct 10 ms 208 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 0 ms 208 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 6 ms 208 KB Output is correct
27 Correct 0 ms 208 KB Output is correct
28 Correct 0 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 14 ms 304 KB Output is correct
33 Correct 75 ms 304 KB Output is correct
34 Correct 44 ms 300 KB Output is correct
35 Correct 75 ms 300 KB Output is correct
36 Correct 45 ms 296 KB Output is correct
37 Correct 77 ms 300 KB Output is correct
38 Correct 49 ms 208 KB Output is correct
39 Correct 49 ms 296 KB Output is correct
40 Correct 65 ms 208 KB Output is correct
41 Correct 75 ms 208 KB Output is correct
42 Correct 67 ms 208 KB Output is correct
43 Correct 50 ms 208 KB Output is correct
44 Correct 48 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 208 KB Output is correct
2 Correct 52 ms 208 KB Output is correct
3 Correct 82 ms 208 KB Output is correct
4 Correct 80 ms 208 KB Output is correct
5 Correct 59 ms 208 KB Output is correct
6 Correct 61 ms 208 KB Output is correct
7 Correct 47 ms 208 KB Output is correct
8 Correct 78 ms 296 KB Output is correct
9 Correct 75 ms 300 KB Output is correct
10 Correct 64 ms 208 KB Output is correct
11 Correct 80 ms 208 KB Output is correct
12 Correct 81 ms 208 KB Output is correct
13 Correct 70 ms 208 KB Output is correct
14 Correct 48 ms 208 KB Output is correct
15 Correct 50 ms 208 KB Output is correct
16 Correct 48 ms 208 KB Output is correct
17 Correct 72 ms 208 KB Output is correct
18 Correct 31 ms 208 KB Output is correct