Submission #477662

# Submission time Handle Problem Language Result Execution time Memory
477662 2021-10-03T02:04:19 Z HappyPacMan Minerals (JOI19_minerals) C++14
40 / 100
56 ms 6180 KB
#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;

int curr = 0;

bool change(int u){
    int nxt = Query(u);
    bool res = (nxt != curr);
    curr = nxt;
    return res;
}

void Solve(int N){
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    vector<int> group[2];
    for(int i=1;i<=2*N;i++) group[change(i)].emplace_back(i);
    shuffle(group[0].begin(),group[0].end(),rng);
    int l[N],r[N];
    vector<int> mid[N];
    for(int i=0;i<N;i++){
        l[i] = 0;
        r[i] = N-1;
        mid[r[i] - (382*(r[i]-l[i]+1)/1000)].emplace_back(i);
    }
    // for(auto u : group[0]) cout << u << ' '; cout << '\n';
    // for(auto u : group[1]) cout << u << ' '; cout << '\n';
    int found = 0;
    while(found < N){
        // for(int i=0;i<N;i++) cout << l[i] << ' '; cout << '\n';
        // for(int i=0;i<N;i++) cout << r[i] << ' '; cout << '\n'; cout << '\n';
        int lmin = N, rmax = 0;
        for(int i=0;i<N;i++){
            lmin = min(lmin,l[i]);
            rmax = max(rmax,r[i]);
        }
        for(int i=rmax;i>=lmin;i--){
            change(group[0][i]);
            vector<int> curr = mid[i];
            mid[i].clear();
            for(auto u : curr){
                bool nxt = change(group[1][u]);
                if(nxt){
                    l[u] = i;
                    int nxm = l[u] + (618*(r[u]-l[u]+1)/1000);
                    if(nxm == r[u]) nxm--;
                    // cout << "nxm 1 : " << group[0][i] << ' ' << group[1][u] << ' ' << nxm << ' ' << r[u] << ' ' << l[u] << '\n';
                    if(l[u] == r[u]){
                        Answer(group[0][l[u]],group[1][u]);
                        found++;
                    }else mid[nxm].emplace_back(u);
                }else{
                    r[u] = i-1;
                    int nxm = r[u] - (382*(r[u]-l[u]+1)/1000);
                    // cout << "nxm 2 : " << group[0][i] << ' ' << group[1][u] << ' ' << nxm << ' ' << r[u] << ' ' << l[u] << '\n';
                    if(l[u] == r[u]){
                        Answer(group[0][l[u]],group[1][u]);
                        found++;
                    }else mid[nxm].emplace_back(u);
                }
            }
        }
        for(int i=lmin;i<rmax;i++){
            change(group[0][i]);
            vector<int> curr = mid[i];
            mid[i].clear();
            for(auto u : curr){
                bool nxt = change(group[1][u]);
                if(nxt){
                    l[u] = i+1;
                    int nxm = l[u] + (382*(r[u]-l[u]+1)/1000);
                    // cout << "nxm 3 : " << group[0][i] << ' ' << group[1][u] << ' ' << nxm << ' ' << r[u] << ' ' << l[u] << '\n';
                    if(l[u] == r[u]){
                        Answer(group[0][l[u]],group[1][u]);
                        found++;
                    }else mid[nxm].emplace_back(u);
                }else{
                    r[u] = i;
                    int nxm = r[u] - (618*(r[u]-l[u]+1)/1000);
                    if(nxm == l[u]) nxm++;
                    // cout << "nxm 4 : " << group[0][i] << ' ' << group[1][u] << ' ' << nxm << ' ' << r[u] << ' ' << l[u] << '\n';
                    if(l[u] == r[u]){
                        Answer(group[0][l[u]],group[1][u]);
                        found++;
                    }else mid[nxm].emplace_back(u);
                }
            }
        }
    }
}   
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 328 KB Output is correct
2 Correct 3 ms 584 KB Output is correct
3 Correct 7 ms 868 KB Output is correct
4 Correct 13 ms 1464 KB Output is correct
5 Correct 24 ms 2496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 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 2 ms 328 KB Output is correct
6 Correct 3 ms 584 KB Output is correct
7 Correct 7 ms 868 KB Output is correct
8 Correct 13 ms 1464 KB Output is correct
9 Correct 24 ms 2496 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 15 ms 1736 KB Output is correct
12 Correct 25 ms 2664 KB Output is correct
13 Correct 24 ms 2616 KB Output is correct
14 Correct 24 ms 2608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 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 2 ms 328 KB Output is correct
6 Correct 3 ms 584 KB Output is correct
7 Correct 7 ms 868 KB Output is correct
8 Correct 13 ms 1464 KB Output is correct
9 Correct 24 ms 2496 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 15 ms 1736 KB Output is correct
12 Correct 25 ms 2664 KB Output is correct
13 Correct 24 ms 2616 KB Output is correct
14 Correct 24 ms 2608 KB Output is correct
15 Incorrect 56 ms 6180 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 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 2 ms 328 KB Output is correct
6 Correct 3 ms 584 KB Output is correct
7 Correct 7 ms 868 KB Output is correct
8 Correct 13 ms 1464 KB Output is correct
9 Correct 24 ms 2496 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 15 ms 1736 KB Output is correct
12 Correct 25 ms 2664 KB Output is correct
13 Correct 24 ms 2616 KB Output is correct
14 Correct 24 ms 2608 KB Output is correct
15 Incorrect 56 ms 6180 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 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 2 ms 328 KB Output is correct
6 Correct 3 ms 584 KB Output is correct
7 Correct 7 ms 868 KB Output is correct
8 Correct 13 ms 1464 KB Output is correct
9 Correct 24 ms 2496 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 15 ms 1736 KB Output is correct
12 Correct 25 ms 2664 KB Output is correct
13 Correct 24 ms 2616 KB Output is correct
14 Correct 24 ms 2608 KB Output is correct
15 Incorrect 56 ms 6180 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 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 2 ms 328 KB Output is correct
6 Correct 3 ms 584 KB Output is correct
7 Correct 7 ms 868 KB Output is correct
8 Correct 13 ms 1464 KB Output is correct
9 Correct 24 ms 2496 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 15 ms 1736 KB Output is correct
12 Correct 25 ms 2664 KB Output is correct
13 Correct 24 ms 2616 KB Output is correct
14 Correct 24 ms 2608 KB Output is correct
15 Incorrect 56 ms 6180 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 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 2 ms 328 KB Output is correct
6 Correct 3 ms 584 KB Output is correct
7 Correct 7 ms 868 KB Output is correct
8 Correct 13 ms 1464 KB Output is correct
9 Correct 24 ms 2496 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 15 ms 1736 KB Output is correct
12 Correct 25 ms 2664 KB Output is correct
13 Correct 24 ms 2616 KB Output is correct
14 Correct 24 ms 2608 KB Output is correct
15 Incorrect 56 ms 6180 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 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 2 ms 328 KB Output is correct
6 Correct 3 ms 584 KB Output is correct
7 Correct 7 ms 868 KB Output is correct
8 Correct 13 ms 1464 KB Output is correct
9 Correct 24 ms 2496 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 15 ms 1736 KB Output is correct
12 Correct 25 ms 2664 KB Output is correct
13 Correct 24 ms 2616 KB Output is correct
14 Correct 24 ms 2608 KB Output is correct
15 Incorrect 56 ms 6180 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -