Submission #891323

# Submission time Handle Problem Language Result Execution time Memory
891323 2023-12-22T18:51:23 Z SorahISA Monster Game (JOI21_monster) C++17
25 / 100
120 ms 1120 KB
#ifndef SorahISA
#define SorahISA
#include SorahISA __FILE__ SorahISA

namespace {

mt19937_64 rng(880301);

} /// end of unnamed namespace

vector<int> solve_small(int N, vector<int> id) {
    vector<int> S(N);
    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];
    }
    
    vector<int> weak, strong;
    for (int i = 0; i < N; ++i) {
        if (win[i] == 1) weak.eb(i);
        if (win[i] == N-2) strong.eb(i);
        if (1 < win[i] and win[i] < N-2) S[i] = win[i];
    }
    
    if (Query(id[weak[0]], id[weak[1]])) S[weak[0]] = 0, S[weak[1]] = 1;
    else                                 S[weak[0]] = 1, S[weak[1]] = 0;
    
    if (Query(id[strong[0]], id[strong[1]])) S[strong[0]] = N-2, S[strong[1]] = N-1;
    else                                     S[strong[0]] = N-1, S[strong[1]] = N-2;
    
    return S;
}

vector<int> solve_large(int N, vector<int> id) {
    vector<int> S(N);
    
    function<void(int, int, vector<int>&)> recur = [&](int L, int R, vector<int> &vec) {
        int n = R - L + 1;
        if (n <= 15) {
            auto _S = solve_small(n, vec);
            for (int i = 0; i < n; ++i) S[vec[i]] = _S[i] + L;
            return;
        }
        
        vector<int> lo, hi;
        while (true) {
            lo.clear(), lo.shrink_to_fit();
            hi.clear(), hi.shrink_to_fit();
            int pos = rng() % (n-1) + 1; swap(vec[0], vec[pos]);
            for (int i = 1; i < n; ++i) {
                (Query(vec[0], vec[i]) ? lo : hi).eb(vec[i]);
            }
            if (SZ(lo) >= 4 and SZ(hi) >= 4) { S[vec[0]] = L + SZ(lo); break; }
        }
        
        int lo_mx = 0, hi_mn = 0;
        for (int i = 1; i < SZ(lo); ++i) { if (Query(lo[i], lo[lo_mx])) lo_mx = i; }
        for (int i = 1; i < SZ(hi); ++i) { if (Query(hi[hi_mn], hi[i])) hi_mn = i; }
        swap(lo[lo_mx], hi[hi_mn]);
        
        // debug(L, R, vec);
        // debug(lo);
        // debug(hi);
        
        int M = L + SZ(lo);
        recur(L, M-1, lo);
        recur(M+1, R, hi);
    };
    
    recur(0, N-1, id);
    
    return S;
}

vector<int> Solve(int N) {
    vector<int> id(N); iota(ALL(id), 0);
    return solve_large(N, id);
}

#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 1 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 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 12 ms 600 KB Output is correct
17 Correct 11 ms 344 KB Output is correct
18 Correct 13 ms 440 KB Output is correct
19 Correct 12 ms 600 KB Output is correct
20 Correct 17 ms 600 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 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 11 ms 600 KB Output is correct
27 Correct 0 ms 596 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 11 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 1 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 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 12 ms 600 KB Output is correct
17 Correct 11 ms 344 KB Output is correct
18 Correct 13 ms 440 KB Output is correct
19 Correct 12 ms 600 KB Output is correct
20 Correct 17 ms 600 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 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 11 ms 600 KB Output is correct
27 Correct 0 ms 596 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 11 ms 600 KB Output is correct
33 Correct 80 ms 956 KB Output is correct
34 Correct 120 ms 952 KB Output is correct
35 Correct 82 ms 852 KB Output is correct
36 Correct 90 ms 692 KB Output is correct
37 Correct 107 ms 600 KB Output is correct
38 Correct 112 ms 712 KB Output is correct
39 Correct 75 ms 600 KB Output is correct
40 Correct 80 ms 960 KB Output is correct
41 Correct 89 ms 696 KB Output is correct
42 Correct 93 ms 1108 KB Output is correct
43 Correct 100 ms 600 KB Output is correct
44 Correct 91 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 94 ms 600 KB Partially correct
2 Partially correct 85 ms 860 KB Partially correct
3 Partially correct 120 ms 692 KB Partially correct
4 Partially correct 86 ms 1112 KB Partially correct
5 Partially correct 83 ms 856 KB Partially correct
6 Partially correct 83 ms 1112 KB Partially correct
7 Partially correct 78 ms 848 KB Partially correct
8 Partially correct 89 ms 712 KB Partially correct
9 Partially correct 84 ms 856 KB Partially correct
10 Partially correct 89 ms 948 KB Partially correct
11 Partially correct 96 ms 604 KB Partially correct
12 Partially correct 93 ms 600 KB Partially correct
13 Incorrect 115 ms 1120 KB Wrong Answer [6]
14 Halted 0 ms 0 KB -