#include "minerals.h"
using namespace std;
#include <vector>
#include <iostream>
int query(int x){
return Query(x+1);
}
int n;
struct mineral{
int a,b;
bool f;
mineral(){a=0;b=n;f=true;}
};
vector<mineral> v;
vector<int> l;
vector<int> r;
void Solve(int N) {
int a,b,c,q,x,y,z,t;
n=N;
v.resize(n,mineral());
b=0;
for (int i=0;i<2*n;i++){
a=query(i);
if (a>b){
l.push_back(i);
b=a;
}else{
r.push_back(i);
}
}
t=0;
for (int i=n/2;i<n;i++){c=query(l[i]);v[i].f=false;}
vector<pair<int,int>> w;
vector<pair<int,int>> w2;
w.push_back({0,N});
while (!w.empty()){
// cout<<'\n';
// for (int i=0;i<n;i++){cout<<l[i]+1<<'\t';}cout<<'\n';
// for (int i=0;i<n;i++){cout<<v[i].f<<'\t';}cout<<'\n';
for (int i=0;i<n;i++){
if (v[i].a+1==v[i].b){continue;}
q=query(r[i]);
if (c!=q){
v[i].a=(v[i].a+v[i].b)/2;
c=q;
}else{
v[i].b=(v[i].a+v[i].b)/2;
}
if (v[i].a+1==v[i].b){t++;}
if (t==n-1){break;}
//cerr<<r[i]+1<<':'<<v[i].a<<','<<v[i].b<<';';
}
if (t==n-1){break;}
q=w.size();
for (int i=0;i<q;i++){
a=w[w.size()-1].first;
b=w[w.size()-1].second;
w.pop_back();
if (a+1==b || a==b){continue;}
y=(a+b)/2;
x=(a+y)/2;
z=(y+b)/2;
for (int j=x;j<y;j++){
c=query(l[j]);
v[j].f=!v[j].f;
}
for (int j=y;j<z;j++){
c=query(l[j]);
v[j].f=!v[j].f;
}
w2.push_back({a,y});
w2.push_back({y,b});
}
w=w2;
w2.clear();
}
if (t==n-1){
vector<bool> zz;
zz.resize(n,true);
for (int i=0;i<n;i++){
if (v[i].a+1==v[i].b){
zz[v[i].a]=false;
}else{
a=i;
}
}
for (int i=0;i<n;i++){
if (zz[i]){v[a].a=i;}
}}
for (int i=0;i<n;i++){
Answer(r[i]+1,l[v[i].a]+1);
}
}
Compilation message
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:47:13: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
47 | if (c!=q){
| ^~
minerals.cpp:92:23: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
92 | if (zz[i]){v[a].a=i;}
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
600 KB |
Output is correct |
4 |
Correct |
4 ms |
856 KB |
Output is correct |
5 |
Correct |
6 ms |
1324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
4 ms |
856 KB |
Output is correct |
9 |
Correct |
6 ms |
1324 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
1028 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
6 ms |
1368 KB |
Output is correct |
14 |
Correct |
7 ms |
1624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
4 ms |
856 KB |
Output is correct |
9 |
Correct |
6 ms |
1324 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
1028 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
6 ms |
1368 KB |
Output is correct |
14 |
Correct |
7 ms |
1624 KB |
Output is correct |
15 |
Correct |
17 ms |
3076 KB |
Output is correct |
16 |
Correct |
17 ms |
3068 KB |
Output is correct |
17 |
Correct |
11 ms |
2944 KB |
Output is correct |
18 |
Correct |
12 ms |
3084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
4 ms |
856 KB |
Output is correct |
9 |
Correct |
6 ms |
1324 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
1028 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
6 ms |
1368 KB |
Output is correct |
14 |
Correct |
7 ms |
1624 KB |
Output is correct |
15 |
Correct |
17 ms |
3076 KB |
Output is correct |
16 |
Correct |
17 ms |
3068 KB |
Output is correct |
17 |
Correct |
11 ms |
2944 KB |
Output is correct |
18 |
Correct |
12 ms |
3084 KB |
Output is correct |
19 |
Correct |
22 ms |
3208 KB |
Output is correct |
20 |
Correct |
19 ms |
3212 KB |
Output is correct |
21 |
Correct |
14 ms |
3200 KB |
Output is correct |
22 |
Correct |
12 ms |
3044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
4 ms |
856 KB |
Output is correct |
9 |
Correct |
6 ms |
1324 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
1028 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
6 ms |
1368 KB |
Output is correct |
14 |
Correct |
7 ms |
1624 KB |
Output is correct |
15 |
Correct |
17 ms |
3076 KB |
Output is correct |
16 |
Correct |
17 ms |
3068 KB |
Output is correct |
17 |
Correct |
11 ms |
2944 KB |
Output is correct |
18 |
Correct |
12 ms |
3084 KB |
Output is correct |
19 |
Correct |
22 ms |
3208 KB |
Output is correct |
20 |
Correct |
19 ms |
3212 KB |
Output is correct |
21 |
Correct |
14 ms |
3200 KB |
Output is correct |
22 |
Correct |
12 ms |
3044 KB |
Output is correct |
23 |
Incorrect |
18 ms |
2648 KB |
Wrong Answer [2] |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
4 ms |
856 KB |
Output is correct |
9 |
Correct |
6 ms |
1324 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
1028 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
6 ms |
1368 KB |
Output is correct |
14 |
Correct |
7 ms |
1624 KB |
Output is correct |
15 |
Correct |
17 ms |
3076 KB |
Output is correct |
16 |
Correct |
17 ms |
3068 KB |
Output is correct |
17 |
Correct |
11 ms |
2944 KB |
Output is correct |
18 |
Correct |
12 ms |
3084 KB |
Output is correct |
19 |
Correct |
22 ms |
3208 KB |
Output is correct |
20 |
Correct |
19 ms |
3212 KB |
Output is correct |
21 |
Correct |
14 ms |
3200 KB |
Output is correct |
22 |
Correct |
12 ms |
3044 KB |
Output is correct |
23 |
Incorrect |
18 ms |
2648 KB |
Wrong Answer [2] |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
4 ms |
856 KB |
Output is correct |
9 |
Correct |
6 ms |
1324 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
1028 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
6 ms |
1368 KB |
Output is correct |
14 |
Correct |
7 ms |
1624 KB |
Output is correct |
15 |
Correct |
17 ms |
3076 KB |
Output is correct |
16 |
Correct |
17 ms |
3068 KB |
Output is correct |
17 |
Correct |
11 ms |
2944 KB |
Output is correct |
18 |
Correct |
12 ms |
3084 KB |
Output is correct |
19 |
Correct |
22 ms |
3208 KB |
Output is correct |
20 |
Correct |
19 ms |
3212 KB |
Output is correct |
21 |
Correct |
14 ms |
3200 KB |
Output is correct |
22 |
Correct |
12 ms |
3044 KB |
Output is correct |
23 |
Incorrect |
18 ms |
2648 KB |
Wrong Answer [2] |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
4 ms |
856 KB |
Output is correct |
9 |
Correct |
6 ms |
1324 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
1028 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
6 ms |
1368 KB |
Output is correct |
14 |
Correct |
7 ms |
1624 KB |
Output is correct |
15 |
Correct |
17 ms |
3076 KB |
Output is correct |
16 |
Correct |
17 ms |
3068 KB |
Output is correct |
17 |
Correct |
11 ms |
2944 KB |
Output is correct |
18 |
Correct |
12 ms |
3084 KB |
Output is correct |
19 |
Correct |
22 ms |
3208 KB |
Output is correct |
20 |
Correct |
19 ms |
3212 KB |
Output is correct |
21 |
Correct |
14 ms |
3200 KB |
Output is correct |
22 |
Correct |
12 ms |
3044 KB |
Output is correct |
23 |
Incorrect |
18 ms |
2648 KB |
Wrong Answer [2] |
24 |
Halted |
0 ms |
0 KB |
- |