#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> llp;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
int N;
int rep[151];
vi reps;
void normalizereps() {
set<int> S;
for (int i = 1; i <= N; i++) S.insert(rep[i]);
unordered_map<int, int> tbl;
int cnt = 1;
while (!S.empty()) {
int x = *S.begin();
S.erase(S.begin());
tbl[x] = cnt++;
}
for (int i = 1; i <= N; i++) rep[i] = tbl[ rep[i] ];
}
int ask(int x) {
cout << reps.size()+1 << " ";
for (int i = 0; i < reps.size(); i++) {
cout << reps[i] << " ";
}
cout << x << endl;
int ret; cin >> ret;
return ret;
}
int ask(int l, int r, int x) {
cout << r-l+2 << " ";
for (int i = l; i <= r; i++) {
cout << reps[i] << " ";
}
cout << x << endl;
int ret; cin >> ret;
return ret;
}
int findrep(int x) {
int l = 0, r = reps.size();
while (r > l) {
int mid = (l + r) / 2;
int n = ask(l, mid, x);
if (n == mid-l+2) l = mid+1;
else r = mid;
}
cerr << "l: " << l << endl;
return reps[l];
}
int main(int argc, char **argv) {
cin >> N;
for (int i = 1; i <= N; i++) rep[i] = i;
reps.pb(1);
for (int i = 2; i <= N; i++) {
int n = ask(i);
if (n == reps.size()+1) {
reps.pb(i);
}
else {
rep[i] = findrep(i);
}
}
normalizereps();
cout << "0 ";
for (int i = 1; i <= N; i++) {
cout << rep[i] << " ";
}
cout << endl;
return 0;
}
Compilation message
carnival.cpp: In function 'int ask(int)':
carnival.cpp:33:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < reps.size(); i++) {
^
carnival.cpp: In function 'int main(int, char**)':
carnival.cpp:69:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (n == reps.size()+1) {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2028 KB |
Output is correct |
2 |
Correct |
3 ms |
2028 KB |
Output is correct |
3 |
Correct |
0 ms |
2028 KB |
Output is correct |
4 |
Correct |
0 ms |
2028 KB |
Output is correct |
5 |
Correct |
9 ms |
2028 KB |
Output is correct |
6 |
Correct |
3 ms |
2028 KB |
Output is correct |
7 |
Correct |
3 ms |
2028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2028 KB |
Output is correct |
2 |
Correct |
0 ms |
2028 KB |
Output is correct |
3 |
Correct |
9 ms |
2028 KB |
Output is correct |
4 |
Correct |
3 ms |
2028 KB |
Output is correct |
5 |
Correct |
6 ms |
2028 KB |
Output is correct |
6 |
Correct |
3 ms |
2028 KB |
Output is correct |
7 |
Correct |
6 ms |
2028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2028 KB |
Output is correct |
2 |
Correct |
3 ms |
2028 KB |
Output is correct |
3 |
Correct |
6 ms |
2028 KB |
Output is correct |
4 |
Correct |
3 ms |
2028 KB |
Output is correct |
5 |
Correct |
3 ms |
2028 KB |
Output is correct |
6 |
Correct |
3 ms |
2028 KB |
Output is correct |
7 |
Correct |
3 ms |
2028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2028 KB |
Output is correct |
2 |
Correct |
3 ms |
2028 KB |
Output is correct |
3 |
Correct |
3 ms |
2028 KB |
Output is correct |
4 |
Correct |
3 ms |
2028 KB |
Output is correct |
5 |
Correct |
3 ms |
2028 KB |
Output is correct |
6 |
Correct |
0 ms |
2028 KB |
Output is correct |
7 |
Correct |
6 ms |
2028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2028 KB |
Output is correct |
2 |
Correct |
0 ms |
2028 KB |
Output is correct |
3 |
Correct |
0 ms |
2028 KB |
Output is correct |
4 |
Correct |
3 ms |
2028 KB |
Output is correct |
5 |
Correct |
6 ms |
2028 KB |
Output is correct |
6 |
Correct |
0 ms |
2028 KB |
Output is correct |
7 |
Correct |
3 ms |
2028 KB |
Output is correct |