#include<bits/stdc++.h>
#include "library.h"
#define F first
#define S second
#define sz(x) (int)x.size()
#define pb push_back
using namespace std;
bool SEND = 1;
int n, a[2222];
int ask (const std::vector < int > &m) {
if (SEND) {
return Query(m);
}
int n = (int)m.size();
int res = 0;
for (int i = 0, j = 0; i < n; i ++) {
j = i;
while (j < n && m[a[j]]) j ++;
if (m[a[i]]) {
res ++;
// cerr << i << ' ' << j << '\n';
}
i = j;
}
/*cerr << "Que " << res << '\n';
for (auto it : m) {
cerr << it << ' ';
}
cout << '\n'; */
assert(res > 0);
return res;
}
void print (const std:: vector <int> &res) {
if (SEND) {
Answer(res);
} else {
for (auto x : res)
cout << x << ' ';
cout << '\n';
exit(0);
}
}
int go (int n, int x, vector < int > &vec) {
vector < int > all;
for (int i = 0; i < n; i ++) if (vec[i]) {
all.pb(i);
}
//cerr << all.size() << ' ' << x << '\n';
assert(all.size() > 0);
if (all.size() == 1) {
return all.back();
}
vector < int > p1(n, 0);
vector < int > p2(n, 0);
for (int i = 0; i < all.size(); i ++) {
if (i < all.size() / 2) {
p1[all[i]] = 1;
// cerr << all[i] << " r :";
} else {
p2[all[i]] = 1;
// cerr << all[i] << " w :";
}
}
int was = ask(p1);
//cerr << was << '\n';
p1[x] = 1;
if (ask(p1) == was) {
p1[x] = 0;
// cerr << "tur1\n";
return go(n, x, p1);
}
//cerr << "tur2\n";
return go(n, x, p2);
}
void Solve(int n) {
if (n == 1) {
print({1});
return;
}
if (n == 2) {
print({1, 2});
return;
}
vector < int > m(n, 1);
int start = -1;
for (int i = 0; i < n; i ++) {
m[i] = 0;
if (ask(m) == 1) {
start = i;
break;
}
m[i] = 1;
}
vector < int > ans;
ans.pb(start);
// cout << start << '\n';
// exit(0);
for (int i = 1; i < n; i ++) {
vector < int > vec(n, 1);
for (auto x : ans) vec[x] = 0;
int x = go(n, ans.back(), vec);
// cout << i << ' ' << x << '\n';
ans.pb(x);
}
for (auto &to : ans) to++;
if (sz(ans) == n - 1) {
cout << "wtf";
exit(0);
}
print(ans);
}
// B...a
Compilation message
library.cpp: In function 'int go(int, int, std::vector<int>&)':
library.cpp:69:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < all.size(); i ++) {
~~^~~~~~~~~~~~
library.cpp:70:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (i < all.size() / 2) {
~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
248 KB |
# of queries: 2375 |
2 |
Correct |
45 ms |
376 KB |
# of queries: 2409 |
3 |
Correct |
49 ms |
248 KB |
# of queries: 2648 |
4 |
Correct |
33 ms |
320 KB |
# of queries: 2595 |
5 |
Correct |
46 ms |
376 KB |
# of queries: 2508 |
6 |
Correct |
37 ms |
320 KB |
# of queries: 2551 |
7 |
Correct |
51 ms |
248 KB |
# of queries: 2544 |
8 |
Correct |
48 ms |
376 KB |
# of queries: 2420 |
9 |
Correct |
50 ms |
376 KB |
# of queries: 2546 |
10 |
Correct |
25 ms |
528 KB |
# of queries: 1474 |
11 |
Correct |
2 ms |
248 KB |
# of queries: 0 |
12 |
Correct |
2 ms |
248 KB |
# of queries: 0 |
13 |
Correct |
2 ms |
376 KB |
# of queries: 4 |
14 |
Correct |
2 ms |
376 KB |
# of queries: 7 |
15 |
Correct |
3 ms |
252 KB |
# of queries: 77 |
16 |
Correct |
4 ms |
320 KB |
# of queries: 183 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
248 KB |
# of queries: 2375 |
2 |
Correct |
45 ms |
376 KB |
# of queries: 2409 |
3 |
Correct |
49 ms |
248 KB |
# of queries: 2648 |
4 |
Correct |
33 ms |
320 KB |
# of queries: 2595 |
5 |
Correct |
46 ms |
376 KB |
# of queries: 2508 |
6 |
Correct |
37 ms |
320 KB |
# of queries: 2551 |
7 |
Correct |
51 ms |
248 KB |
# of queries: 2544 |
8 |
Correct |
48 ms |
376 KB |
# of queries: 2420 |
9 |
Correct |
50 ms |
376 KB |
# of queries: 2546 |
10 |
Correct |
25 ms |
528 KB |
# of queries: 1474 |
11 |
Correct |
2 ms |
248 KB |
# of queries: 0 |
12 |
Correct |
2 ms |
248 KB |
# of queries: 0 |
13 |
Correct |
2 ms |
376 KB |
# of queries: 4 |
14 |
Correct |
2 ms |
376 KB |
# of queries: 7 |
15 |
Correct |
3 ms |
252 KB |
# of queries: 77 |
16 |
Correct |
4 ms |
320 KB |
# of queries: 183 |
17 |
Correct |
528 ms |
420 KB |
# of queries: 17982 |
18 |
Correct |
503 ms |
476 KB |
# of queries: 17293 |
19 |
Correct |
501 ms |
504 KB |
# of queries: 17467 |
20 |
Correct |
482 ms |
376 KB |
# of queries: 16325 |
21 |
Correct |
433 ms |
504 KB |
# of queries: 15324 |
22 |
Correct |
506 ms |
504 KB |
# of queries: 17669 |
23 |
Correct |
518 ms |
416 KB |
# of queries: 17224 |
24 |
Correct |
172 ms |
248 KB |
# of queries: 7915 |
25 |
Correct |
524 ms |
376 KB |
# of queries: 17136 |
26 |
Correct |
473 ms |
536 KB |
# of queries: 15963 |
27 |
Correct |
208 ms |
248 KB |
# of queries: 8040 |
28 |
Correct |
465 ms |
504 KB |
# of queries: 15957 |
29 |
Correct |
442 ms |
408 KB |
# of queries: 15939 |
30 |
Correct |
445 ms |
328 KB |
# of queries: 15957 |