Submission #501668

# Submission time Handle Problem Language Result Execution time Memory
501668 2022-01-04T09:38:59 Z 79brue Minerals (JOI19_minerals) C++14
90 / 100
48 ms 2816 KB
#include "minerals.h"
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

int n;
bool chk[100002];
int order[100002], ocnt;
int ans[100002];
bool in[100002];
int lastRet;

int query(int x){
    in[x] = !in[x];
    return Query(order[x]);
}

void solve(int l, int r, vector<int>& vec){
    if(l==r){
        ans[l] = vec[0];
        return;
    }
    int m = (l+r)>>1;
    if(r-m < m-l+1) m--;

    int tmpCalc = 0;
    bool st = 0;
    for(int i=l; i<=m; i++) if(!in[i]) tmpCalc++;
    for(int i=m+1; i<=r; i++) if(in[i]) tmpCalc++;
    if(tmpCalc * 2 > r-l+1) st = 1;

    for(int i=l; i<=m; i++){
        if(in[i] == st) lastRet = query(i);
    }
    for(int i=m+1; i<=r; i++){
        if(in[i] != st) lastRet = query(i);
    }

    vector<int> lVec, rVec;
    for(auto x: vec){
        if((int)lVec.size() == m-l+1){
            rVec.push_back(x);
            continue;
        }
        else if((int)rVec.size() == r-m){
            lVec.push_back(x);
            continue;
        }
        int tmp = query(x);
        if((tmp == lastRet) ^ st) lVec.push_back(x);
        else rVec.push_back(x);
        lastRet = tmp;
    }

    solve(l, m, lVec);
    solve(m+1, r, rVec);
}

void Solve(int N){
    n = N;
    for(int i=1; i<=n+n; i++){
        int tmp = Query(i);
        if(tmp != lastRet) order[++ocnt] = i, chk[i] = 1;
        lastRet = tmp;
        in[i] = 1;
    }
    for(int i=1; i<=n+n; i++) if(!chk[i]) order[++ocnt] = i;
    random_shuffle(order+1, order+n+1);
    random_shuffle(order+n+1, order+n+n+1);

    vector<int> tVec;
    for(int i=n+1; i<=n+n; i++) tVec.push_back(i);
    solve(1, n, tVec);
    for(int i=1; i<=n; i++) Answer(order[i], order[ans[i]]);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 3 ms 328 KB Output is correct
3 Correct 3 ms 456 KB Output is correct
4 Correct 8 ms 712 KB Output is correct
5 Correct 13 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 3 ms 328 KB Output is correct
7 Correct 3 ms 456 KB Output is correct
8 Correct 8 ms 712 KB Output is correct
9 Correct 13 ms 1112 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 8 ms 888 KB Output is correct
12 Correct 12 ms 1216 KB Output is correct
13 Correct 11 ms 1188 KB Output is correct
14 Correct 11 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 3 ms 328 KB Output is correct
7 Correct 3 ms 456 KB Output is correct
8 Correct 8 ms 712 KB Output is correct
9 Correct 13 ms 1112 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 8 ms 888 KB Output is correct
12 Correct 12 ms 1216 KB Output is correct
13 Correct 11 ms 1188 KB Output is correct
14 Correct 11 ms 1024 KB Output is correct
15 Correct 36 ms 2664 KB Output is correct
16 Correct 48 ms 2512 KB Output is correct
17 Correct 36 ms 2676 KB Output is correct
18 Correct 44 ms 2468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 3 ms 328 KB Output is correct
7 Correct 3 ms 456 KB Output is correct
8 Correct 8 ms 712 KB Output is correct
9 Correct 13 ms 1112 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 8 ms 888 KB Output is correct
12 Correct 12 ms 1216 KB Output is correct
13 Correct 11 ms 1188 KB Output is correct
14 Correct 11 ms 1024 KB Output is correct
15 Correct 36 ms 2664 KB Output is correct
16 Correct 48 ms 2512 KB Output is correct
17 Correct 36 ms 2676 KB Output is correct
18 Correct 44 ms 2468 KB Output is correct
19 Correct 36 ms 2716 KB Output is correct
20 Correct 37 ms 2380 KB Output is correct
21 Correct 38 ms 2452 KB Output is correct
22 Correct 35 ms 2472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 3 ms 328 KB Output is correct
7 Correct 3 ms 456 KB Output is correct
8 Correct 8 ms 712 KB Output is correct
9 Correct 13 ms 1112 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 8 ms 888 KB Output is correct
12 Correct 12 ms 1216 KB Output is correct
13 Correct 11 ms 1188 KB Output is correct
14 Correct 11 ms 1024 KB Output is correct
15 Correct 36 ms 2664 KB Output is correct
16 Correct 48 ms 2512 KB Output is correct
17 Correct 36 ms 2676 KB Output is correct
18 Correct 44 ms 2468 KB Output is correct
19 Correct 36 ms 2716 KB Output is correct
20 Correct 37 ms 2380 KB Output is correct
21 Correct 38 ms 2452 KB Output is correct
22 Correct 35 ms 2472 KB Output is correct
23 Correct 36 ms 2568 KB Output is correct
24 Correct 37 ms 2696 KB Output is correct
25 Correct 42 ms 2800 KB Output is correct
26 Correct 36 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 3 ms 328 KB Output is correct
7 Correct 3 ms 456 KB Output is correct
8 Correct 8 ms 712 KB Output is correct
9 Correct 13 ms 1112 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 8 ms 888 KB Output is correct
12 Correct 12 ms 1216 KB Output is correct
13 Correct 11 ms 1188 KB Output is correct
14 Correct 11 ms 1024 KB Output is correct
15 Correct 36 ms 2664 KB Output is correct
16 Correct 48 ms 2512 KB Output is correct
17 Correct 36 ms 2676 KB Output is correct
18 Correct 44 ms 2468 KB Output is correct
19 Correct 36 ms 2716 KB Output is correct
20 Correct 37 ms 2380 KB Output is correct
21 Correct 38 ms 2452 KB Output is correct
22 Correct 35 ms 2472 KB Output is correct
23 Correct 36 ms 2568 KB Output is correct
24 Correct 37 ms 2696 KB Output is correct
25 Correct 42 ms 2800 KB Output is correct
26 Correct 36 ms 2260 KB Output is correct
27 Correct 47 ms 2628 KB Output is correct
28 Correct 39 ms 2780 KB Output is correct
29 Correct 36 ms 2648 KB Output is correct
30 Correct 42 ms 2564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 3 ms 328 KB Output is correct
7 Correct 3 ms 456 KB Output is correct
8 Correct 8 ms 712 KB Output is correct
9 Correct 13 ms 1112 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 8 ms 888 KB Output is correct
12 Correct 12 ms 1216 KB Output is correct
13 Correct 11 ms 1188 KB Output is correct
14 Correct 11 ms 1024 KB Output is correct
15 Correct 36 ms 2664 KB Output is correct
16 Correct 48 ms 2512 KB Output is correct
17 Correct 36 ms 2676 KB Output is correct
18 Correct 44 ms 2468 KB Output is correct
19 Correct 36 ms 2716 KB Output is correct
20 Correct 37 ms 2380 KB Output is correct
21 Correct 38 ms 2452 KB Output is correct
22 Correct 35 ms 2472 KB Output is correct
23 Correct 36 ms 2568 KB Output is correct
24 Correct 37 ms 2696 KB Output is correct
25 Correct 42 ms 2800 KB Output is correct
26 Correct 36 ms 2260 KB Output is correct
27 Correct 47 ms 2628 KB Output is correct
28 Correct 39 ms 2780 KB Output is correct
29 Correct 36 ms 2648 KB Output is correct
30 Correct 42 ms 2564 KB Output is correct
31 Correct 42 ms 2728 KB Output is correct
32 Correct 45 ms 2776 KB Output is correct
33 Correct 41 ms 2816 KB Output is correct
34 Correct 38 ms 2340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 3 ms 328 KB Output is correct
7 Correct 3 ms 456 KB Output is correct
8 Correct 8 ms 712 KB Output is correct
9 Correct 13 ms 1112 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 8 ms 888 KB Output is correct
12 Correct 12 ms 1216 KB Output is correct
13 Correct 11 ms 1188 KB Output is correct
14 Correct 11 ms 1024 KB Output is correct
15 Correct 36 ms 2664 KB Output is correct
16 Correct 48 ms 2512 KB Output is correct
17 Correct 36 ms 2676 KB Output is correct
18 Correct 44 ms 2468 KB Output is correct
19 Correct 36 ms 2716 KB Output is correct
20 Correct 37 ms 2380 KB Output is correct
21 Correct 38 ms 2452 KB Output is correct
22 Correct 35 ms 2472 KB Output is correct
23 Correct 36 ms 2568 KB Output is correct
24 Correct 37 ms 2696 KB Output is correct
25 Correct 42 ms 2800 KB Output is correct
26 Correct 36 ms 2260 KB Output is correct
27 Correct 47 ms 2628 KB Output is correct
28 Correct 39 ms 2780 KB Output is correct
29 Correct 36 ms 2648 KB Output is correct
30 Correct 42 ms 2564 KB Output is correct
31 Correct 42 ms 2728 KB Output is correct
32 Correct 45 ms 2776 KB Output is correct
33 Correct 41 ms 2816 KB Output is correct
34 Correct 38 ms 2340 KB Output is correct
35 Incorrect 45 ms 2500 KB Wrong Answer [2]
36 Halted 0 ms 0 KB -