#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for (int i=(n-1); i>=0; --i)
#define REP1(i,n) FOR(i,1,n+1)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif
const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;
#include "library.h"
int query(vector<int> &a) {
if (*max_element(ALL(a)) == 0) assert(0);
return Query(a);
}
#ifdef BALBIT
#define debug(x) cout<<#x<<" is "<<x<<endl
#else
#define debug(x)
#endif
void rem(vector<int> &a, int num) {
int x = 0;
for (;x<SZ(a) && a[x]!=num; x++);
for (int i = x; i<SZ(a)-1; i++) {
swap(a[i], a[i+1]);
}
a.pop_back();
}
void Solve(int n)
{
if (n==1) {
Answer({1}); return;
}
int start = -1;
vector<int> M(n,1);
REP(i,n) {
M[i] = 0;
int Q = query(M);
M[i] = 1;
if (Q == 1) {
start = i; break;
}
}
assert(start != -1);
vector<int> st;
REP(i,n) st.pb(i);
rem(st,start);
vector<int> ans = {start+1};
debug(start);
REP(i,n-1) {
int nxt = 0;
REP(j,10) {
fill(ALL(M),0);
bool chg = 0;
REP(k, SZ(st)) {
if ( k & ( 1<< j )) {
M[st[k]] = 1; chg = 1;
}
}
if (!chg) continue;
int Q1 = query(M);
M[ans.back()-1] = 1;
int Q2 = query(M);
if (Q1 == Q2) {
nxt = nxt | (1<<j);
}
}
debug(st[nxt]+1);
ans.push_back(st[nxt]+1);
rem(st, st[nxt]);
}
Answer(ans);
}
/*
5
4 2 5 3 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
376 KB |
# of queries: 2563 |
2 |
Correct |
48 ms |
248 KB |
# of queries: 2599 |
3 |
Correct |
47 ms |
320 KB |
# of queries: 2816 |
4 |
Correct |
55 ms |
252 KB |
# of queries: 2765 |
5 |
Correct |
34 ms |
312 KB |
# of queries: 2680 |
6 |
Correct |
41 ms |
312 KB |
# of queries: 2727 |
7 |
Correct |
53 ms |
248 KB |
# of queries: 2736 |
8 |
Correct |
49 ms |
376 KB |
# of queries: 2590 |
9 |
Correct |
54 ms |
252 KB |
# of queries: 2710 |
10 |
Correct |
30 ms |
248 KB |
# of queries: 1572 |
11 |
Correct |
2 ms |
248 KB |
# of queries: 0 |
12 |
Correct |
2 ms |
248 KB |
# of queries: 1 |
13 |
Correct |
2 ms |
380 KB |
# of queries: 4 |
14 |
Correct |
2 ms |
376 KB |
# of queries: 7 |
15 |
Correct |
3 ms |
376 KB |
# of queries: 83 |
16 |
Correct |
5 ms |
376 KB |
# of queries: 207 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
376 KB |
# of queries: 2563 |
2 |
Correct |
48 ms |
248 KB |
# of queries: 2599 |
3 |
Correct |
47 ms |
320 KB |
# of queries: 2816 |
4 |
Correct |
55 ms |
252 KB |
# of queries: 2765 |
5 |
Correct |
34 ms |
312 KB |
# of queries: 2680 |
6 |
Correct |
41 ms |
312 KB |
# of queries: 2727 |
7 |
Correct |
53 ms |
248 KB |
# of queries: 2736 |
8 |
Correct |
49 ms |
376 KB |
# of queries: 2590 |
9 |
Correct |
54 ms |
252 KB |
# of queries: 2710 |
10 |
Correct |
30 ms |
248 KB |
# of queries: 1572 |
11 |
Correct |
2 ms |
248 KB |
# of queries: 0 |
12 |
Correct |
2 ms |
248 KB |
# of queries: 1 |
13 |
Correct |
2 ms |
380 KB |
# of queries: 4 |
14 |
Correct |
2 ms |
376 KB |
# of queries: 7 |
15 |
Correct |
3 ms |
376 KB |
# of queries: 83 |
16 |
Correct |
5 ms |
376 KB |
# of queries: 207 |
17 |
Correct |
573 ms |
432 KB |
# of queries: 18794 |
18 |
Correct |
504 ms |
376 KB |
# of queries: 18021 |
19 |
Correct |
564 ms |
328 KB |
# of queries: 18239 |
20 |
Correct |
509 ms |
404 KB |
# of queries: 17075 |
21 |
Correct |
493 ms |
376 KB |
# of queries: 16096 |
22 |
Correct |
574 ms |
376 KB |
# of queries: 18413 |
23 |
Correct |
507 ms |
376 KB |
# of queries: 17994 |
24 |
Correct |
157 ms |
448 KB |
# of queries: 8263 |
25 |
Correct |
546 ms |
328 KB |
# of queries: 17890 |
26 |
Correct |
506 ms |
328 KB |
# of queries: 16769 |
27 |
Correct |
181 ms |
376 KB |
# of queries: 8414 |
28 |
Correct |
550 ms |
376 KB |
# of queries: 17935 |
29 |
Correct |
542 ms |
328 KB |
# of queries: 17915 |
30 |
Correct |
534 ms |
376 KB |
# of queries: 17935 |