Submission #804271

# Submission time Handle Problem Language Result Execution time Memory
804271 2023-08-03T07:44:03 Z fatemetmhr Monster Game (JOI21_monster) C++17
77 / 100
171 ms 4352 KB
//  ~ Be Name Khoda ~  //

#include "monster.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")

using namespace std;

typedef long long ll;

#define pb       push_back
#define mp       make_pair
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second

const int maxn  =  1e6   + 10;
const int maxn5 =  1e3   + 10;
const int maxnt =  1.2e6 + 10;
const int maxn3 =  1e3   + 10;
const int mod   =  1e9   + 7;
const ll  inf   =  1e18;

namespace {

int a[maxn5], cnt[maxn5], done[maxn5][maxn5];

bool assk(int a, int b){
    if(done[a][b] == -1){
        done[a][b] = Query(a, b);
        done[b][a] = done[a][b] ^ 1;
    }
    return done[a][b];
}

bool cmp(int i, int j){return cnt[i] < cnt[j] || (cnt[i] == cnt[j] && assk(i, j));}


}  // namespace

std::vector<int> Solve(int n) {
    std::vector<int> ret(n);

    memset(done, -1, sizeof done);

    for(int i = 1; i < n; i++){
        int lo = -1, hi = i;
        while(hi - lo > 1){
            int mid = (lo + hi) >> 1;
            if(assk(a[mid], i))
                hi = mid;
            else
                lo = mid;
        }
        cnt[i] = lo + 1;
        for(int j = hi; j < i; j++)
            cnt[a[j]]++;
        for(int j = max(0, lo - 4); j < lo; j++) if(!assk(i, a[j])){
            cnt[a[j]]++;
            cnt[i]--;
            //cout << "ha? " << i << ' ' << j << ' ' << a[j] << endl;
        }
        for(int j = hi + 1; j < min(i, hi + 5); j++) if(assk(i, a[j])){
            cnt[a[j]]--;
            cnt[i]++;
        }
        //cout << "* " << i << ' ' << lo << ' ' << hi << ' ' << cnt[i] << ' ' << cnt[0] << endl;
        a[i] = i;
        sort(a, a + i + 1, cmp);
    }
    /*
    for(int i = 0; i < n; i++)
        cout << a[i] << ' ' << cnt[a[i]] << endl;
    cout << endl;
    //*/

    for (int i = 0; i < n; i++)
        ret[a[i]] = i;

    return ret;
}













# Verdict Execution time Memory Grader output
1 Correct 3 ms 4176 KB Output is correct
2 Correct 2 ms 4176 KB Output is correct
3 Correct 2 ms 4176 KB Output is correct
4 Correct 2 ms 4176 KB Output is correct
5 Correct 2 ms 4176 KB Output is correct
6 Correct 2 ms 4176 KB Output is correct
7 Correct 2 ms 4176 KB Output is correct
8 Correct 2 ms 4176 KB Output is correct
9 Correct 2 ms 4176 KB Output is correct
10 Correct 2 ms 4176 KB Output is correct
11 Correct 2 ms 4352 KB Output is correct
12 Correct 2 ms 4340 KB Output is correct
13 Correct 2 ms 4176 KB Output is correct
14 Correct 2 ms 4176 KB Output is correct
15 Correct 2 ms 4176 KB Output is correct
16 Correct 17 ms 4176 KB Output is correct
17 Correct 24 ms 4176 KB Output is correct
18 Correct 15 ms 4176 KB Output is correct
19 Correct 12 ms 4176 KB Output is correct
20 Correct 21 ms 4176 KB Output is correct
21 Correct 2 ms 4176 KB Output is correct
22 Correct 2 ms 4176 KB Output is correct
23 Correct 2 ms 4176 KB Output is correct
24 Correct 2 ms 4176 KB Output is correct
25 Correct 2 ms 4176 KB Output is correct
26 Correct 16 ms 4176 KB Output is correct
27 Correct 2 ms 4176 KB Output is correct
28 Correct 2 ms 4176 KB Output is correct
29 Correct 2 ms 4176 KB Output is correct
30 Correct 2 ms 4304 KB Output is correct
31 Correct 2 ms 4176 KB Output is correct
32 Correct 16 ms 4176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4176 KB Output is correct
2 Correct 2 ms 4176 KB Output is correct
3 Correct 2 ms 4176 KB Output is correct
4 Correct 2 ms 4176 KB Output is correct
5 Correct 2 ms 4176 KB Output is correct
6 Correct 2 ms 4176 KB Output is correct
7 Correct 2 ms 4176 KB Output is correct
8 Correct 2 ms 4176 KB Output is correct
9 Correct 2 ms 4176 KB Output is correct
10 Correct 2 ms 4176 KB Output is correct
11 Correct 2 ms 4352 KB Output is correct
12 Correct 2 ms 4340 KB Output is correct
13 Correct 2 ms 4176 KB Output is correct
14 Correct 2 ms 4176 KB Output is correct
15 Correct 2 ms 4176 KB Output is correct
16 Correct 17 ms 4176 KB Output is correct
17 Correct 24 ms 4176 KB Output is correct
18 Correct 15 ms 4176 KB Output is correct
19 Correct 12 ms 4176 KB Output is correct
20 Correct 21 ms 4176 KB Output is correct
21 Correct 2 ms 4176 KB Output is correct
22 Correct 2 ms 4176 KB Output is correct
23 Correct 2 ms 4176 KB Output is correct
24 Correct 2 ms 4176 KB Output is correct
25 Correct 2 ms 4176 KB Output is correct
26 Correct 16 ms 4176 KB Output is correct
27 Correct 2 ms 4176 KB Output is correct
28 Correct 2 ms 4176 KB Output is correct
29 Correct 2 ms 4176 KB Output is correct
30 Correct 2 ms 4304 KB Output is correct
31 Correct 2 ms 4176 KB Output is correct
32 Correct 16 ms 4176 KB Output is correct
33 Correct 156 ms 4176 KB Output is correct
34 Correct 153 ms 4304 KB Output is correct
35 Correct 151 ms 4176 KB Output is correct
36 Correct 158 ms 4176 KB Output is correct
37 Correct 146 ms 4304 KB Output is correct
38 Correct 101 ms 4176 KB Output is correct
39 Correct 86 ms 4352 KB Output is correct
40 Correct 128 ms 4296 KB Output is correct
41 Correct 110 ms 4296 KB Output is correct
42 Correct 145 ms 4176 KB Output is correct
43 Correct 71 ms 4296 KB Output is correct
44 Correct 143 ms 4176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 171 ms 4176 KB Partially correct
2 Partially correct 135 ms 4352 KB Partially correct
3 Partially correct 140 ms 4304 KB Partially correct
4 Partially correct 152 ms 4176 KB Partially correct
5 Partially correct 126 ms 4176 KB Partially correct
6 Partially correct 130 ms 4176 KB Partially correct
7 Partially correct 127 ms 4300 KB Partially correct
8 Partially correct 111 ms 4176 KB Partially correct
9 Partially correct 167 ms 4176 KB Partially correct
10 Partially correct 164 ms 4176 KB Partially correct
11 Partially correct 154 ms 4304 KB Partially correct
12 Partially correct 131 ms 4176 KB Partially correct
13 Partially correct 135 ms 4300 KB Partially correct
14 Partially correct 156 ms 4176 KB Partially correct
15 Partially correct 107 ms 4176 KB Partially correct
16 Partially correct 155 ms 4296 KB Partially correct
17 Partially correct 84 ms 4304 KB Partially correct
18 Partially correct 113 ms 4176 KB Partially correct