Submission #815780

# Submission time Handle Problem Language Result Execution time Memory
815780 2023-08-08T23:05:26 Z JakobZorz Minerals (JOI19_minerals) C++14
100 / 100
50 ms 4980 KB
#include"minerals.h"
#include<iostream>
#include<vector>
using namespace std;

int inside;
int last;
int flag[100000];
int query(int a){
    flag[a]++;
    flag[a]%=2;
    if(flag[a])
        inside++;
    else
        inside--;
    last=Query(a);
    return last;
}

void solve(vector<int>up,vector<int>dn,bool inv){
    //cout<<up.size()<<" "<<dn.size()<<"\n";
    
    if(up.size()==1){
        Answer(up[0],dn[0]);
        return;
    }
    
    vector<int>up1,up2;
    vector<int>dn1,dn2;
    int mid;
    if(inv){
        mid=(int)(up.size()*2)/3;
    }else
        mid=(int)(up.size()+2)/3;
    
    for(int i=0;i<mid;i++)
        up1.push_back(up[i]);
    for(int i=mid;i<(int)up.size();i++)
        up2.push_back(up[i]);
    
    if(inv)
        for(int i:up2)
            query(i);
    else
        for(int i:up1)
            query(i);
    
    for(int i:dn){
        if(dn1.size()==up1.size()){
            dn2.push_back(i);
            continue;
        }
        
        if(dn2.size()==up2.size()){
            dn1.push_back(i);
            continue;
        }
        
        int prev=last;
        query(i);
        bool to_first=prev==last;
        
        if(to_first)
            dn1.push_back(i);
        else
            dn2.push_back(i);
    }
    
    solve(up1,dn1,true);
    solve(up2,dn2,false);
}

void Solve(int N){
    vector<int>elements;
    for(int i=1;i<=2*N;i++)
        elements.push_back(i);
    for(int i=0;i<2*N;i++)
        swap(elements[i],elements[rand()%(2*N)]);
    
    vector<int>up,dn;
    int prev=0;
    for(int i:elements){
        query(i);
        if(last!=prev)
            up.push_back(i);
        else
            dn.push_back(i);
        prev=last;
    }
    
    solve(up,dn,true);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 5 ms 720 KB Output is correct
4 Correct 7 ms 1136 KB Output is correct
5 Correct 12 ms 1824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 5 ms 720 KB Output is correct
8 Correct 7 ms 1136 KB Output is correct
9 Correct 12 ms 1824 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1436 KB Output is correct
12 Correct 14 ms 1872 KB Output is correct
13 Correct 12 ms 1872 KB Output is correct
14 Correct 12 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 5 ms 720 KB Output is correct
8 Correct 7 ms 1136 KB Output is correct
9 Correct 12 ms 1824 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1436 KB Output is correct
12 Correct 14 ms 1872 KB Output is correct
13 Correct 12 ms 1872 KB Output is correct
14 Correct 12 ms 1920 KB Output is correct
15 Correct 35 ms 4416 KB Output is correct
16 Correct 34 ms 4424 KB Output is correct
17 Correct 42 ms 4412 KB Output is correct
18 Correct 35 ms 4268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 5 ms 720 KB Output is correct
8 Correct 7 ms 1136 KB Output is correct
9 Correct 12 ms 1824 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1436 KB Output is correct
12 Correct 14 ms 1872 KB Output is correct
13 Correct 12 ms 1872 KB Output is correct
14 Correct 12 ms 1920 KB Output is correct
15 Correct 35 ms 4416 KB Output is correct
16 Correct 34 ms 4424 KB Output is correct
17 Correct 42 ms 4412 KB Output is correct
18 Correct 35 ms 4268 KB Output is correct
19 Correct 35 ms 4544 KB Output is correct
20 Correct 36 ms 4444 KB Output is correct
21 Correct 36 ms 4608 KB Output is correct
22 Correct 35 ms 4352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 5 ms 720 KB Output is correct
8 Correct 7 ms 1136 KB Output is correct
9 Correct 12 ms 1824 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1436 KB Output is correct
12 Correct 14 ms 1872 KB Output is correct
13 Correct 12 ms 1872 KB Output is correct
14 Correct 12 ms 1920 KB Output is correct
15 Correct 35 ms 4416 KB Output is correct
16 Correct 34 ms 4424 KB Output is correct
17 Correct 42 ms 4412 KB Output is correct
18 Correct 35 ms 4268 KB Output is correct
19 Correct 35 ms 4544 KB Output is correct
20 Correct 36 ms 4444 KB Output is correct
21 Correct 36 ms 4608 KB Output is correct
22 Correct 35 ms 4352 KB Output is correct
23 Correct 38 ms 4672 KB Output is correct
24 Correct 44 ms 4596 KB Output is correct
25 Correct 45 ms 4540 KB Output is correct
26 Correct 45 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 5 ms 720 KB Output is correct
8 Correct 7 ms 1136 KB Output is correct
9 Correct 12 ms 1824 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1436 KB Output is correct
12 Correct 14 ms 1872 KB Output is correct
13 Correct 12 ms 1872 KB Output is correct
14 Correct 12 ms 1920 KB Output is correct
15 Correct 35 ms 4416 KB Output is correct
16 Correct 34 ms 4424 KB Output is correct
17 Correct 42 ms 4412 KB Output is correct
18 Correct 35 ms 4268 KB Output is correct
19 Correct 35 ms 4544 KB Output is correct
20 Correct 36 ms 4444 KB Output is correct
21 Correct 36 ms 4608 KB Output is correct
22 Correct 35 ms 4352 KB Output is correct
23 Correct 38 ms 4672 KB Output is correct
24 Correct 44 ms 4596 KB Output is correct
25 Correct 45 ms 4540 KB Output is correct
26 Correct 45 ms 4444 KB Output is correct
27 Correct 43 ms 4696 KB Output is correct
28 Correct 41 ms 4684 KB Output is correct
29 Correct 38 ms 4756 KB Output is correct
30 Correct 41 ms 4536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 5 ms 720 KB Output is correct
8 Correct 7 ms 1136 KB Output is correct
9 Correct 12 ms 1824 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1436 KB Output is correct
12 Correct 14 ms 1872 KB Output is correct
13 Correct 12 ms 1872 KB Output is correct
14 Correct 12 ms 1920 KB Output is correct
15 Correct 35 ms 4416 KB Output is correct
16 Correct 34 ms 4424 KB Output is correct
17 Correct 42 ms 4412 KB Output is correct
18 Correct 35 ms 4268 KB Output is correct
19 Correct 35 ms 4544 KB Output is correct
20 Correct 36 ms 4444 KB Output is correct
21 Correct 36 ms 4608 KB Output is correct
22 Correct 35 ms 4352 KB Output is correct
23 Correct 38 ms 4672 KB Output is correct
24 Correct 44 ms 4596 KB Output is correct
25 Correct 45 ms 4540 KB Output is correct
26 Correct 45 ms 4444 KB Output is correct
27 Correct 43 ms 4696 KB Output is correct
28 Correct 41 ms 4684 KB Output is correct
29 Correct 38 ms 4756 KB Output is correct
30 Correct 41 ms 4536 KB Output is correct
31 Correct 40 ms 4824 KB Output is correct
32 Correct 49 ms 4952 KB Output is correct
33 Correct 43 ms 4868 KB Output is correct
34 Correct 38 ms 4680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 5 ms 720 KB Output is correct
8 Correct 7 ms 1136 KB Output is correct
9 Correct 12 ms 1824 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 8 ms 1436 KB Output is correct
12 Correct 14 ms 1872 KB Output is correct
13 Correct 12 ms 1872 KB Output is correct
14 Correct 12 ms 1920 KB Output is correct
15 Correct 35 ms 4416 KB Output is correct
16 Correct 34 ms 4424 KB Output is correct
17 Correct 42 ms 4412 KB Output is correct
18 Correct 35 ms 4268 KB Output is correct
19 Correct 35 ms 4544 KB Output is correct
20 Correct 36 ms 4444 KB Output is correct
21 Correct 36 ms 4608 KB Output is correct
22 Correct 35 ms 4352 KB Output is correct
23 Correct 38 ms 4672 KB Output is correct
24 Correct 44 ms 4596 KB Output is correct
25 Correct 45 ms 4540 KB Output is correct
26 Correct 45 ms 4444 KB Output is correct
27 Correct 43 ms 4696 KB Output is correct
28 Correct 41 ms 4684 KB Output is correct
29 Correct 38 ms 4756 KB Output is correct
30 Correct 41 ms 4536 KB Output is correct
31 Correct 40 ms 4824 KB Output is correct
32 Correct 49 ms 4952 KB Output is correct
33 Correct 43 ms 4868 KB Output is correct
34 Correct 38 ms 4680 KB Output is correct
35 Correct 50 ms 4960 KB Output is correct
36 Correct 40 ms 4980 KB Output is correct
37 Correct 39 ms 4972 KB Output is correct
38 Correct 43 ms 4784 KB Output is correct