#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({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) {
~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
320 KB |
# of queries: 2375 |
2 |
Correct |
37 ms |
320 KB |
# of queries: 2409 |
3 |
Correct |
49 ms |
248 KB |
# of queries: 2648 |
4 |
Correct |
43 ms |
376 KB |
# of queries: 2595 |
5 |
Correct |
51 ms |
248 KB |
# of queries: 2508 |
6 |
Correct |
33 ms |
316 KB |
# of queries: 2551 |
7 |
Correct |
33 ms |
320 KB |
# of queries: 2544 |
8 |
Correct |
47 ms |
376 KB |
# of queries: 2420 |
9 |
Correct |
33 ms |
376 KB |
# of queries: 2546 |
10 |
Correct |
21 ms |
412 KB |
# of queries: 1474 |
11 |
Correct |
2 ms |
248 KB |
# of queries: 0 |
12 |
Incorrect |
2 ms |
404 KB |
Wrong Answer [4] |
13 |
Correct |
2 ms |
252 KB |
# of queries: 4 |
14 |
Correct |
2 ms |
376 KB |
# of queries: 7 |
15 |
Correct |
3 ms |
248 KB |
# of queries: 77 |
16 |
Correct |
4 ms |
320 KB |
# of queries: 183 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
320 KB |
# of queries: 2375 |
2 |
Correct |
37 ms |
320 KB |
# of queries: 2409 |
3 |
Correct |
49 ms |
248 KB |
# of queries: 2648 |
4 |
Correct |
43 ms |
376 KB |
# of queries: 2595 |
5 |
Correct |
51 ms |
248 KB |
# of queries: 2508 |
6 |
Correct |
33 ms |
316 KB |
# of queries: 2551 |
7 |
Correct |
33 ms |
320 KB |
# of queries: 2544 |
8 |
Correct |
47 ms |
376 KB |
# of queries: 2420 |
9 |
Correct |
33 ms |
376 KB |
# of queries: 2546 |
10 |
Correct |
21 ms |
412 KB |
# of queries: 1474 |
11 |
Correct |
2 ms |
248 KB |
# of queries: 0 |
12 |
Incorrect |
2 ms |
404 KB |
Wrong Answer [4] |
13 |
Correct |
2 ms |
252 KB |
# of queries: 4 |
14 |
Correct |
2 ms |
376 KB |
# of queries: 7 |
15 |
Correct |
3 ms |
248 KB |
# of queries: 77 |
16 |
Correct |
4 ms |
320 KB |
# of queries: 183 |
17 |
Correct |
523 ms |
328 KB |
# of queries: 17982 |
18 |
Correct |
423 ms |
460 KB |
# of queries: 17293 |
19 |
Correct |
489 ms |
504 KB |
# of queries: 17467 |
20 |
Correct |
455 ms |
320 KB |
# of queries: 16325 |
21 |
Correct |
435 ms |
504 KB |
# of queries: 15324 |
22 |
Correct |
494 ms |
376 KB |
# of queries: 17669 |
23 |
Correct |
449 ms |
412 KB |
# of queries: 17224 |
24 |
Correct |
176 ms |
380 KB |
# of queries: 7915 |
25 |
Correct |
491 ms |
420 KB |
# of queries: 17136 |
26 |
Correct |
448 ms |
408 KB |
# of queries: 15963 |
27 |
Correct |
158 ms |
376 KB |
# of queries: 8040 |
28 |
Correct |
435 ms |
376 KB |
# of queries: 15957 |
29 |
Correct |
442 ms |
408 KB |
# of queries: 15939 |
30 |
Correct |
453 ms |
424 KB |
# of queries: 15957 |