Submission #795810

# Submission time Handle Problem Language Result Execution time Memory
795810 2023-07-27T15:51:27 Z hugo_pm Monster Game (JOI21_monster) C++17
100 / 100
82 ms 320 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 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 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 0 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 13 ms 208 KB Output is correct
17 Correct 12 ms 312 KB Output is correct
18 Correct 12 ms 208 KB Output is correct
19 Correct 10 ms 304 KB Output is correct
20 Correct 13 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 0 ms 208 KB Output is correct
23 Correct 1 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 13 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 0 ms 208 KB Output is correct
32 Correct 8 ms 280 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 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 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 0 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 13 ms 208 KB Output is correct
17 Correct 12 ms 312 KB Output is correct
18 Correct 12 ms 208 KB Output is correct
19 Correct 10 ms 304 KB Output is correct
20 Correct 13 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 0 ms 208 KB Output is correct
23 Correct 1 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 13 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 0 ms 208 KB Output is correct
32 Correct 8 ms 280 KB Output is correct
33 Correct 72 ms 320 KB Output is correct
34 Correct 71 ms 312 KB Output is correct
35 Correct 67 ms 208 KB Output is correct
36 Correct 65 ms 208 KB Output is correct
37 Correct 54 ms 300 KB Output is correct
38 Correct 58 ms 208 KB Output is correct
39 Correct 82 ms 208 KB Output is correct
40 Correct 76 ms 208 KB Output is correct
41 Correct 54 ms 208 KB Output is correct
42 Correct 81 ms 208 KB Output is correct
43 Correct 79 ms 208 KB Output is correct
44 Correct 55 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 208 KB Output is correct
2 Correct 81 ms 304 KB Output is correct
3 Correct 74 ms 208 KB Output is correct
4 Correct 67 ms 208 KB Output is correct
5 Correct 60 ms 208 KB Output is correct
6 Correct 64 ms 208 KB Output is correct
7 Correct 41 ms 208 KB Output is correct
8 Correct 78 ms 300 KB Output is correct
9 Correct 81 ms 300 KB Output is correct
10 Correct 76 ms 208 KB Output is correct
11 Correct 79 ms 208 KB Output is correct
12 Correct 60 ms 208 KB Output is correct
13 Correct 68 ms 208 KB Output is correct
14 Correct 48 ms 208 KB Output is correct
15 Correct 38 ms 208 KB Output is correct
16 Correct 35 ms 208 KB Output is correct
17 Correct 53 ms 208 KB Output is correct
18 Correct 41 ms 208 KB Output is correct