// #pragma GCC optimize("O3","unroll-loops")
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
// #define
// #define int long long
#define all(v) v.begin(), v.end()
#define fi first
#define se second
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
// declare
/*int Query(vector <int> m){
for (int x : m) cout << x << ' ';
cout << "\n";
fflush(stdout);
int ans;
cin >> ans;
return ans;
}
void Answer(vector <int> v){
for (int x : v) cout << x << ' ';
cout << "\n";
fflush(stdout);
}*/
void Solve(int n)
{
if (n <= 2){
vector <int> ans;
for (int i = 1; i <= n; ++i) ans.push_back(i);
Answer(ans);
return;
}
int idx;
vector <int> m(n, 1);
for (int i = 1; i <= n; ++i)
{
m[i - 1] = 0;
int ans = Query(m);
if (ans == 1)
{
idx = i;
break;
}
m[i - 1] = 1;
}
vector <int> ans = {idx};
vector <bool> vs(n + 5, false);
for (int i = 1; i < n; ++i){
vs[idx] = true;
vector <int> now;
for (int j = 1; j <= n; ++j)
if (!vs[j])
now.push_back(j);
int l = 1, r = now.size();
while (l < r){
int md = l + r >> 1;
vector <int> m(n, 0);
for (int i = l; i <= md; ++i)
m[now[i - 1] - 1] = 1;
int c1 = Query(m);
m[idx - 1] = 1;
int c2 = Query(m);
if (c1 == c2) r = md;
else l = md + 1;
}
ans.push_back(now[l - 1]);
idx = now[l - 1];
}
Answer(ans);
}
// 4 2 5 3 1
/*signed main()
{
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int t = 1, n;
// cin >> t;
cin >> n;
while (t--)
Solve(n);
cerr << "\nTIME: " << 1000 * clock() / CLOCKS_PER_SEC << "ms.";
}*/
Compilation message
library.cpp: In function 'void Solve(int)':
library.cpp:61:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
61 | int md = l + r >> 1;
| ~~^~~
library.cpp:38:9: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
38 | int idx;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
344 KB |
# of queries: 2387 |
2 |
Correct |
24 ms |
344 KB |
# of queries: 2433 |
3 |
Correct |
32 ms |
344 KB |
# of queries: 2638 |
4 |
Correct |
20 ms |
344 KB |
# of queries: 2593 |
5 |
Correct |
24 ms |
344 KB |
# of queries: 2504 |
6 |
Correct |
14 ms |
356 KB |
# of queries: 2553 |
7 |
Correct |
17 ms |
596 KB |
# of queries: 2568 |
8 |
Correct |
28 ms |
596 KB |
# of queries: 2402 |
9 |
Correct |
23 ms |
344 KB |
# of queries: 2512 |
10 |
Correct |
13 ms |
344 KB |
# of queries: 1478 |
11 |
Correct |
0 ms |
344 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
344 KB |
# of queries: 0 |
13 |
Correct |
0 ms |
344 KB |
# of queries: 4 |
14 |
Correct |
0 ms |
344 KB |
# of queries: 7 |
15 |
Correct |
1 ms |
344 KB |
# of queries: 73 |
16 |
Correct |
2 ms |
344 KB |
# of queries: 187 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
344 KB |
# of queries: 2387 |
2 |
Correct |
24 ms |
344 KB |
# of queries: 2433 |
3 |
Correct |
32 ms |
344 KB |
# of queries: 2638 |
4 |
Correct |
20 ms |
344 KB |
# of queries: 2593 |
5 |
Correct |
24 ms |
344 KB |
# of queries: 2504 |
6 |
Correct |
14 ms |
356 KB |
# of queries: 2553 |
7 |
Correct |
17 ms |
596 KB |
# of queries: 2568 |
8 |
Correct |
28 ms |
596 KB |
# of queries: 2402 |
9 |
Correct |
23 ms |
344 KB |
# of queries: 2512 |
10 |
Correct |
13 ms |
344 KB |
# of queries: 1478 |
11 |
Correct |
0 ms |
344 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
344 KB |
# of queries: 0 |
13 |
Correct |
0 ms |
344 KB |
# of queries: 4 |
14 |
Correct |
0 ms |
344 KB |
# of queries: 7 |
15 |
Correct |
1 ms |
344 KB |
# of queries: 73 |
16 |
Correct |
2 ms |
344 KB |
# of queries: 187 |
17 |
Correct |
225 ms |
432 KB |
# of queries: 18008 |
18 |
Correct |
206 ms |
600 KB |
# of queries: 17231 |
19 |
Correct |
243 ms |
444 KB |
# of queries: 17451 |
20 |
Correct |
200 ms |
428 KB |
# of queries: 16277 |
21 |
Correct |
166 ms |
448 KB |
# of queries: 15362 |
22 |
Correct |
201 ms |
444 KB |
# of queries: 17617 |
23 |
Correct |
184 ms |
344 KB |
# of queries: 17170 |
24 |
Correct |
93 ms |
436 KB |
# of queries: 7885 |
25 |
Correct |
194 ms |
344 KB |
# of queries: 17118 |
26 |
Correct |
178 ms |
432 KB |
# of queries: 15989 |
27 |
Correct |
78 ms |
424 KB |
# of queries: 7994 |
28 |
Correct |
193 ms |
344 KB |
# of queries: 17935 |
29 |
Correct |
226 ms |
436 KB |
# of queries: 17915 |
30 |
Correct |
211 ms |
428 KB |
# of queries: 17935 |