#include "minerals.h"
#include <vector>
#include <fstream>
#include <map>
void Solve(int N) {
int col[2*N+1];
for(int i = 0; i < 2*N+1; i++){
col[i] = 0;
}
int c = 0;
int in[N+1];
for(int i = 0; i <= N; i++)
in[i] = 0;
int pos[N+1];
bool is[2*N+1];
bool was[2*N+1];
for(int i = 0; i <= 2*N; i++) in[i] = was[i] = false;
int sz = 0;
int mx[2*N+1];
for(int i = 0; i <= 2*N; i++) mx[i] = 0;
int cnt[2*N+1];
for(int i = 0; i <= 2*N; i++) cnt[i] = 0;
for(int i = 1; i <= 2*N; i++){
int cur = Query(i);
if(cur != sz){
sz = cur;
pos[cur] = i;
is[i] = 1;
in[cur] = 1;
col[i] = sz;
was[i] = true;
} else {
sz = Query(i);
}
mx[i] = sz;
}
cnt[0] = N;
bool answered[N+1];
for(int i = 0; i <= N; i++)
answered[i] = false;
for(int bt = 0; (1 << bt) <= N; bt++){
for(int i = 1; i <= N; i++){
if(answered[i])
continue;
if(in[i] && (i >> bt & 1) == 0){
sz = Query(pos[i]);
in[i] = false;
}
if(!in[i] && (i >> bt & 1) == 1){
sz = Query(pos[i]);
in[i] = true;
}
}
std::map<int,int> gp;
for(int i = 1; i <= 2*N; i++){
if(was[i])
continue;
if(mx[i] < (1 << bt)){
gp[col[i]] = i;
continue;
}
int nw = Query(i);
if(nw == sz){
cnt[col[i]]--;
col[i] |= (1 << bt);
cnt[col[i]]++;
}
gp[col[i]] = i;
sz = Query(i);
}
for(int i = 1; i <= N; i++){
if(cnt[i] == 1 && !answered[i]){
// printf("pair %d %d\n",gp[i],pos[i]);
Answer(gp[i],pos[i]);
answered[i] = true;
was[gp[i]] = true;
if(in[i]){
sz = Query(pos[i]);
}
}
}
}
// for(int i = 1; i <= 2*N; i++){
// printf("col[%d] = %d\n",i,col[i]);
// }
std::vector<int> A[N+1];
for(int i = 1; i <= 2*N; i++){
A[col[i]].push_back(i);
}
for(int i = 1; i <= N; i++){
if(!answered[i])
Answer(A[i][0],A[i][1]);
}
return;
}
/**
4
1 5
2 6
3 4
7 8
**/
Compilation message
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:11:9: warning: unused variable 'c' [-Wunused-variable]
11 | int c = 0;
| ^
minerals.cpp:16:10: warning: variable 'is' set but not used [-Wunused-but-set-variable]
16 | bool is[2*N+1];
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
3 ms |
592 KB |
Output is correct |
3 |
Correct |
7 ms |
828 KB |
Output is correct |
4 |
Correct |
16 ms |
1360 KB |
Output is correct |
5 |
Correct |
28 ms |
2220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
7 ms |
828 KB |
Output is correct |
8 |
Correct |
16 ms |
1360 KB |
Output is correct |
9 |
Correct |
28 ms |
2220 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
18 ms |
1620 KB |
Output is correct |
12 |
Correct |
29 ms |
2324 KB |
Output is correct |
13 |
Correct |
17 ms |
2256 KB |
Output is correct |
14 |
Correct |
20 ms |
2244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
7 ms |
828 KB |
Output is correct |
8 |
Correct |
16 ms |
1360 KB |
Output is correct |
9 |
Correct |
28 ms |
2220 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
18 ms |
1620 KB |
Output is correct |
12 |
Correct |
29 ms |
2324 KB |
Output is correct |
13 |
Correct |
17 ms |
2256 KB |
Output is correct |
14 |
Correct |
20 ms |
2244 KB |
Output is correct |
15 |
Incorrect |
34 ms |
2488 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
7 ms |
828 KB |
Output is correct |
8 |
Correct |
16 ms |
1360 KB |
Output is correct |
9 |
Correct |
28 ms |
2220 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
18 ms |
1620 KB |
Output is correct |
12 |
Correct |
29 ms |
2324 KB |
Output is correct |
13 |
Correct |
17 ms |
2256 KB |
Output is correct |
14 |
Correct |
20 ms |
2244 KB |
Output is correct |
15 |
Incorrect |
34 ms |
2488 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
7 ms |
828 KB |
Output is correct |
8 |
Correct |
16 ms |
1360 KB |
Output is correct |
9 |
Correct |
28 ms |
2220 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
18 ms |
1620 KB |
Output is correct |
12 |
Correct |
29 ms |
2324 KB |
Output is correct |
13 |
Correct |
17 ms |
2256 KB |
Output is correct |
14 |
Correct |
20 ms |
2244 KB |
Output is correct |
15 |
Incorrect |
34 ms |
2488 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
7 ms |
828 KB |
Output is correct |
8 |
Correct |
16 ms |
1360 KB |
Output is correct |
9 |
Correct |
28 ms |
2220 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
18 ms |
1620 KB |
Output is correct |
12 |
Correct |
29 ms |
2324 KB |
Output is correct |
13 |
Correct |
17 ms |
2256 KB |
Output is correct |
14 |
Correct |
20 ms |
2244 KB |
Output is correct |
15 |
Incorrect |
34 ms |
2488 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
7 ms |
828 KB |
Output is correct |
8 |
Correct |
16 ms |
1360 KB |
Output is correct |
9 |
Correct |
28 ms |
2220 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
18 ms |
1620 KB |
Output is correct |
12 |
Correct |
29 ms |
2324 KB |
Output is correct |
13 |
Correct |
17 ms |
2256 KB |
Output is correct |
14 |
Correct |
20 ms |
2244 KB |
Output is correct |
15 |
Incorrect |
34 ms |
2488 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
7 ms |
828 KB |
Output is correct |
8 |
Correct |
16 ms |
1360 KB |
Output is correct |
9 |
Correct |
28 ms |
2220 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
18 ms |
1620 KB |
Output is correct |
12 |
Correct |
29 ms |
2324 KB |
Output is correct |
13 |
Correct |
17 ms |
2256 KB |
Output is correct |
14 |
Correct |
20 ms |
2244 KB |
Output is correct |
15 |
Incorrect |
34 ms |
2488 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |