Submission #492639

# Submission time Handle Problem Language Result Execution time Memory
492639 2021-12-08T09:31:49 Z Jarif_Rahman Monster Game (JOI21_monster) C++17
87 / 100
128 ms 8468 KB
#include "monster.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

#ifdef LOCAL
#define debug(v) for(auto x: v) cerr << x << " "; cerr << #v << "\n";
#endif

int do_cnt = 0;
int cnt = 0;

vector<vector<int>> QQ;
vector<vector<int>> extra;
bool query(int a, int b){
    if(a > b){
        extra[b][a] = 0;
        if(QQ[b][a] == -1) QQ[b][a] = Query(b, a), cnt+=do_cnt;
        return !QQ[b][a];
    }
    else{
        extra[a][b] = 0;
        if(QQ[a][b] == -1) QQ[a][b] = Query(a, b), cnt+=do_cnt;
        return QQ[a][b];
    }
}
bool query0(int a, int b){
    if(a > b){
        if(extra[b][a] == -1) extra[b][a] = 1; 
        if(QQ[b][a] == -1) QQ[b][a] = Query(b, a), cnt+=do_cnt;
        return !QQ[b][a];
    }
    else{
        if(extra[a][b] == -1) extra[a][b] = 1;
        if(QQ[a][b] == -1) QQ[a][b] = Query(a, b), cnt+=do_cnt;
        return QQ[a][b];
    }
}

template<typename it>
void merge_sort(it a, it b){
    int n = b-a;
    if(n == 1) return;
    merge_sort(a, a+n/2);
    merge_sort(a+n/2, b);
    int* ab = new int[n];
    merge(a, a+n/2, a+n/2, b, ab, [](int x, int y){
        return query(y, x);
    });
    for(int i = 0; i < n; i++) *(a+i) = *(ab+i);
}

vector<int> Solve(int n){
    QQ = vector<vector<int>>(n, vector<int>(n, -1));
    extra = QQ;

    vector<int> sth(n);
    for(int i = 0; i < n; i++) sth[i] = i;
    do_cnt = 1;
    merge_sort(sth.begin(), sth.end());

    int cnt2 = 0;

    auto win = [&](int x){
        vector<int> rt;
        for(int i = 0; i < n; i++) if(i != x && query0(x, i)) rt.pb(i);
        return rt;
    };

    int n0 = n;
    
    for(int i = 0; i < n0-1; i++){
        if(i == 0){
            auto s0 = win(sth[0]);
            if(s0.size() == 1){
                auto s1 = win(s0[0]);
                if(s1.size() == 1){
                    continue;
                }
            }
        }
        if(i != 0 && query(sth[i-1], sth[i])) continue;
        bool bl = 0;
        for(int j = i+2; j < n0; j++){
            if(query(sth[j], sth[j-2])){
                if((i == 0 && win(sth[j-1]).size() != 1) ||
                    (i != 0 && !query(sth[i-1], sth[j-1]))) 
                    reverse(sth.begin()+i, sth.begin()+j-1);
                else reverse(sth.begin()+i, sth.begin()+j);
                i = j-1;
                bl = 1;
                break;
            }
        }
        if(!bl){
            if((i == 0 && win(sth[n0-1]).size() != 1) ||
                (i != 0 && !query(sth[i-1], sth[n0-1])))
                reverse(sth.begin()+i, sth.begin()+n0-1);
            else reverse(sth.begin()+i, sth.begin()+n0);
            i = n0;
        }
    }

    if(cnt > 13000) exit(-1);

    vector<int> ans(n);
    for(int i = 0; i < n; i++) ans[sth[i]] = i;
    return ans;

}

Compilation message

monster.cpp: In function 'std::vector<int> Solve(int)':
monster.cpp:66:9: warning: unused variable 'cnt2' [-Wunused-variable]
   66 |     int cnt2 = 0;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 0 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 1 ms 200 KB Output is correct
16 Correct 20 ms 584 KB Output is correct
17 Correct 19 ms 584 KB Output is correct
18 Correct 15 ms 584 KB Output is correct
19 Correct 16 ms 584 KB Output is correct
20 Correct 18 ms 624 KB Output is correct
21 Correct 1 ms 200 KB Output is correct
22 Correct 1 ms 200 KB Output is correct
23 Correct 0 ms 200 KB Output is correct
24 Correct 1 ms 200 KB Output is correct
25 Correct 1 ms 200 KB Output is correct
26 Correct 10 ms 584 KB Output is correct
27 Correct 0 ms 200 KB Output is correct
28 Correct 0 ms 200 KB Output is correct
29 Correct 1 ms 200 KB Output is correct
30 Correct 1 ms 200 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 14 ms 584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 0 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 1 ms 200 KB Output is correct
16 Correct 20 ms 584 KB Output is correct
17 Correct 19 ms 584 KB Output is correct
18 Correct 15 ms 584 KB Output is correct
19 Correct 16 ms 584 KB Output is correct
20 Correct 18 ms 624 KB Output is correct
21 Correct 1 ms 200 KB Output is correct
22 Correct 1 ms 200 KB Output is correct
23 Correct 0 ms 200 KB Output is correct
24 Correct 1 ms 200 KB Output is correct
25 Correct 1 ms 200 KB Output is correct
26 Correct 10 ms 584 KB Output is correct
27 Correct 0 ms 200 KB Output is correct
28 Correct 0 ms 200 KB Output is correct
29 Correct 1 ms 200 KB Output is correct
30 Correct 1 ms 200 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 14 ms 584 KB Output is correct
33 Correct 104 ms 8408 KB Output is correct
34 Correct 94 ms 8172 KB Output is correct
35 Correct 111 ms 8276 KB Output is correct
36 Correct 101 ms 8436 KB Output is correct
37 Correct 104 ms 8192 KB Output is correct
38 Correct 93 ms 8236 KB Output is correct
39 Correct 105 ms 8136 KB Output is correct
40 Correct 86 ms 8200 KB Output is correct
41 Correct 112 ms 8204 KB Output is correct
42 Correct 100 ms 8208 KB Output is correct
43 Correct 74 ms 8212 KB Output is correct
44 Correct 67 ms 8204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 111 ms 8276 KB Partially correct
2 Partially correct 124 ms 8444 KB Partially correct
3 Partially correct 128 ms 8208 KB Partially correct
4 Partially correct 100 ms 8136 KB Partially correct
5 Partially correct 84 ms 8468 KB Partially correct
6 Partially correct 80 ms 8136 KB Partially correct
7 Correct 78 ms 8216 KB Output is correct
8 Partially correct 96 ms 8188 KB Partially correct
9 Partially correct 92 ms 8136 KB Partially correct
10 Partially correct 63 ms 8324 KB Partially correct
11 Partially correct 119 ms 8240 KB Partially correct
12 Partially correct 115 ms 8192 KB Partially correct
13 Correct 99 ms 8316 KB Output is correct
14 Correct 70 ms 8204 KB Output is correct
15 Correct 72 ms 8212 KB Output is correct
16 Correct 76 ms 8136 KB Output is correct
17 Partially correct 109 ms 8200 KB Partially correct
18 Correct 74 ms 8212 KB Output is correct