이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |