Submission #891405

# Submission time Handle Problem Language Result Execution time Memory
891405 2023-12-22T21:47:06 Z SorahISA Monster Game (JOI21_monster) C++17
100 / 100
63 ms 856 KB
#ifndef SorahISA
#define SorahISA
#include SorahISA __FILE__ SorahISA

vector<int> Solve(int N) {
    vector<int> id(N); iota(ALL(id), 0);
    
    function<void(int, int)> recur = [&](int L, int R) {
        if (L == R) return;
        int M = (L + R) >> 1;
        recur(L, M), recur(M+1, R);
        inplace_merge(begin(id) + L, begin(id) + M + 1, begin(id) + R + 1, [&](int a, int b) { return !Query(a, b); });
    };
    
    recur(0, N-1);
    
    int n = min(N, int(10));
    vector<int> win(n, 0);
    for (int i = 0; i < n; ++i) for (int j = i+1; j < n; ++j) {
        ++win[Query(id[i], id[j]) ? i : j];
    }
    
    int zero = 0;
    for (int i = 0; i < n; ++i) for (int j = i+1; j < n; ++j) {
        if (win[i] == 1 and win[j] == 1) zero = (Query(id[i], id[j]) ? i : j);
    }
    reverse(begin(id), begin(id) + zero + 1);
    
    for (int lst = zero, now = zero + 1; now < N; ++now) {
        if (Query(id[lst], id[now])) {
            reverse(begin(id) + lst + 1, begin(id) + now + 1);
            lst = now;
        }
    }
    
    vector<int> S(N);
    for (int i = 0; i < N; ++i) S[id[i]] = i;
    return S;
}

#else

#ifdef local
#include "C/monster.h"
#else
#include "monster.h"
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

using int64 = long long;
// #define int int64
using float80 = long double;
// #define double float80
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;

#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())

template <typename T>
ostream & operator << (ostream &os, const vector<T> &vec) {
    os << "[";
    for (int i = 0; i < SZ(vec); ++i) {
        if (i) os << ", ";
        os << vec[i];
    }
    os << "]";
    return os;
}

#ifdef local
#define fastIO() void()
#define debug(...) \
    fprintf(stderr, "\u001b[33m"), \
    fprintf(stderr, "At [%s], line %d: (%s) = ", __FUNCTION__, __LINE__, #__VA_ARGS__), \
    _do(__VA_ARGS__), \
    fprintf(stderr, "\u001b[0m")
template <typename T> void _do(T &&_t) { cerr << _t << "\n"; }
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) { cerr << _t << ", ", _do(_u...); }
#else
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define debug(...) void()
#endif

template <typename T, typename U> bool chmin(T &lhs, U rhs) { return lhs > rhs ? lhs = rhs, 1 : 0; }
template <typename T, typename U> bool chmax(T &lhs, U rhs) { return lhs < rhs ? lhs = rhs, 1 : 0; }

#endif
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 5 ms 600 KB Output is correct
17 Correct 6 ms 600 KB Output is correct
18 Correct 7 ms 600 KB Output is correct
19 Correct 5 ms 600 KB Output is correct
20 Correct 6 ms 600 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 4 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 408 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 4 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 5 ms 600 KB Output is correct
17 Correct 6 ms 600 KB Output is correct
18 Correct 7 ms 600 KB Output is correct
19 Correct 5 ms 600 KB Output is correct
20 Correct 6 ms 600 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 4 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 408 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 4 ms 600 KB Output is correct
33 Correct 51 ms 600 KB Output is correct
34 Correct 50 ms 436 KB Output is correct
35 Correct 42 ms 440 KB Output is correct
36 Correct 44 ms 600 KB Output is correct
37 Correct 49 ms 600 KB Output is correct
38 Correct 36 ms 600 KB Output is correct
39 Correct 42 ms 688 KB Output is correct
40 Correct 44 ms 600 KB Output is correct
41 Correct 48 ms 600 KB Output is correct
42 Correct 46 ms 600 KB Output is correct
43 Correct 29 ms 592 KB Output is correct
44 Correct 27 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 424 KB Output is correct
2 Correct 48 ms 600 KB Output is correct
3 Correct 51 ms 600 KB Output is correct
4 Correct 42 ms 848 KB Output is correct
5 Correct 52 ms 440 KB Output is correct
6 Correct 38 ms 848 KB Output is correct
7 Correct 43 ms 672 KB Output is correct
8 Correct 44 ms 344 KB Output is correct
9 Correct 63 ms 600 KB Output is correct
10 Correct 44 ms 540 KB Output is correct
11 Correct 41 ms 600 KB Output is correct
12 Correct 63 ms 848 KB Output is correct
13 Correct 43 ms 600 KB Output is correct
14 Correct 38 ms 600 KB Output is correct
15 Correct 20 ms 856 KB Output is correct
16 Correct 24 ms 600 KB Output is correct
17 Correct 40 ms 692 KB Output is correct
18 Correct 36 ms 672 KB Output is correct