#include <iostream>
#include <vector>
#include <set>
using namespace::std;
#define FOR(i, b) for(int i = 0; i < b; i++)
#define F0R(i, a, b) for(int i = a; i <= b; i++)
int N;
vector<int> e;
int get(int x){ return e[x] < 0 ? x : e[x] = get(e[x]); }
void unite(int x, int y){
x = get(x), y = get(y);
if(x == y) return;
if(e[x] > e[y]) swap(x, y);
e[x] += e[y];
e[y] = x;
}
int query(int i0, int iN){ //ask grader how many
cout<<iN-i0+1<<" ";
F0R(i, i0, iN-1) cout<<i+1<<" "; cout<<iN<<endl;
int diff; cin>>diff; return diff;
}
void check(int i0, int iN){ //i limits inclusive
if(i0 == iN) return; //only 1
int diff = query(i0, iN);
if(diff == 1){ //all same costume
F0R(i, i0+1, iN) unite(i0, i);
return;
}
//split in half
int half = i0+(iN-i0)/2;
check(i0, half); check(half+1, iN);
set<int> cc1, cc2; //cc reps of first half and second half
F0R(i, i0, half) cc1.insert(get(i));
F0R(i, half+1, iN) cc2.insert(get(i));
for(int c1 : cc1){ //check for overlaps
for(int c2 : cc2){
cout<<2<<" "<<c1+1<<" "<<c2+2<<endl;
int q; cin>>q;
if(q == 1){ unite(c1, c2); break; } //found same costume
}
}
}
int main() {
//freopen("carnival.in", "r", stdin);
//freopen("carnival.out", "w", stdout);
cin>>N;
e = vector<int>(N, -1);
FOR(i, N) cout<<get(i)+1<<endl;
}
Compilation message
carnival.cpp: In function 'int query(int, int)':
carnival.cpp:7:22: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
7 | #define F0R(i, a, b) for(int i = a; i <= b; i++)
| ^~~
carnival.cpp:21:5: note: in expansion of macro 'F0R'
21 | F0R(i, i0, iN-1) cout<<i+1<<" "; cout<<iN<<endl;
| ^~~
carnival.cpp:21:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
21 | F0R(i, i0, iN-1) cout<<i+1<<" "; cout<<iN<<endl;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |