#include "grader.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define ii pair<ll,ll>
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);(s<e?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(123456);
int n;
vector<int> ans;
vector<int> pos; //which pos idk
void shuf(){
rep(x,0,sz(pos)){
swap(ans[pos[x]],ans[pos[rng()%(x+1)]]);
}
}
const int LIM=2;
void solve(int N) {
n=N;
rep(x,1,n+1) ans.pub(x);
rep(x,0,n) pos.pub(x);
int correct=0;
int num=0;
while (true){
int curr;
do{
shuf();
curr=query(ans);
num++;
if (curr==n) return;
} while (curr!=correct);
vector<int> idx;
int avail;
do{
rep(x,0,sz(pos)) swap(pos[x],pos[rng()%(x+1)]);
idx.clear();
for (int x=0;x<sz(pos)-1;x+=2) idx.pub(x);
for (auto &it:idx) swap(ans[pos[it]],ans[pos[it+1]]);
curr=query(ans);
if (curr==n) return;
avail=curr-correct;
for (auto &it:idx) swap(ans[pos[it]],ans[pos[it+1]]);
} while (avail==0);
vector<int> npos;
while (avail){
idx.clear();
for (int x=0;x<sz(pos)-1;x+=2) idx.pub(x);
int nc=correct+avail;
while (sz(idx)!=1){
int temp=sz(idx)/2;
rep(x,0,temp) swap(ans[pos[idx[x]]],ans[pos[idx[x]+1]]);
curr=query(ans);
if (curr==n) return;
bool left=true;
if (curr==correct) left=false;
rep(x,0,temp) swap(ans[pos[idx[x]]],ans[pos[idx[x]+1]]);
vector<int> idx2;
if (left){
rep(x,0,temp) idx2.pub(idx[x]);
nc=curr;
}
else{
rep(x,temp,sz(idx)) idx2.pub(idx[x]);
nc=nc-(curr-correct);
}
swap(idx,idx2);
}
swap(ans[pos[idx[0]]],ans[pos[idx[0]+1]]);
curr=nc;
if (curr==correct+2){
correct+=2;
avail-=2;
}
else{
int temp;
if (!npos.empty()) temp=npos.front();
else if (idx[0]==0) temp=pos.back();
else temp=pos.front();
swap(ans[pos[idx[0]]],ans[temp]);
curr=query(ans);
if (curr==n) return;
swap(ans[pos[idx[0]]],ans[temp]);
if (curr==correct){
npos.pub(pos[idx[0]+1]);
}
else{
npos.pub(pos[idx[0]]);
}
correct++;
avail--;
}
pos.erase(pos.begin()+idx[0]);
pos.erase(pos.begin()+idx[0]);
}
for (auto &it:npos) pos.pub(it);
//cout<<"num left: "<<sz(pos)<<endl;
//for (auto &it:ans) cout<<it<<" "; cout<<endl;
//for (auto &it:pos) cout<<it<<" "; cout<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 17 |
2 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 9 |
3 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 13 |
4 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 22 |
5 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 14 |
6 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 15 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 17 |
2 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 9 |
3 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 13 |
4 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 22 |
5 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 14 |
6 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 15 |
7 |
Correct |
7 ms |
200 KB |
Correct! Number of queries: 400 |
8 |
Correct |
9 ms |
200 KB |
Correct! Number of queries: 400 |
9 |
Correct |
7 ms |
200 KB |
Correct! Number of queries: 400 |
10 |
Correct |
7 ms |
200 KB |
Correct! Number of queries: 400 |
11 |
Correct |
6 ms |
200 KB |
Correct! Number of queries: 300 |
12 |
Correct |
8 ms |
200 KB |
Correct! Number of queries: 400 |
13 |
Correct |
8 ms |
200 KB |
Correct! Number of queries: 400 |
14 |
Correct |
6 ms |
200 KB |
Correct! Number of queries: 400 |
15 |
Correct |
6 ms |
200 KB |
Correct! Number of queries: 400 |
16 |
Correct |
5 ms |
200 KB |
Correct! Number of queries: 400 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 17 |
2 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 9 |
3 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 13 |
4 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 22 |
5 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 14 |
6 |
Correct |
1 ms |
200 KB |
Correct! Number of queries: 15 |
7 |
Correct |
7 ms |
200 KB |
Correct! Number of queries: 400 |
8 |
Correct |
9 ms |
200 KB |
Correct! Number of queries: 400 |
9 |
Correct |
7 ms |
200 KB |
Correct! Number of queries: 400 |
10 |
Correct |
7 ms |
200 KB |
Correct! Number of queries: 400 |
11 |
Correct |
6 ms |
200 KB |
Correct! Number of queries: 300 |
12 |
Correct |
8 ms |
200 KB |
Correct! Number of queries: 400 |
13 |
Correct |
8 ms |
200 KB |
Correct! Number of queries: 400 |
14 |
Correct |
6 ms |
200 KB |
Correct! Number of queries: 400 |
15 |
Correct |
6 ms |
200 KB |
Correct! Number of queries: 400 |
16 |
Correct |
5 ms |
200 KB |
Correct! Number of queries: 400 |
17 |
Correct |
95 ms |
200 KB |
Correct! Number of queries: 2500 |
18 |
Correct |
92 ms |
200 KB |
Correct! Number of queries: 2300 |
19 |
Correct |
85 ms |
200 KB |
Correct! Number of queries: 2300 |
20 |
Correct |
96 ms |
200 KB |
Correct! Number of queries: 2400 |
21 |
Correct |
93 ms |
200 KB |
Correct! Number of queries: 2400 |
22 |
Correct |
87 ms |
200 KB |
Correct! Number of queries: 2300 |
23 |
Correct |
89 ms |
200 KB |
Correct! Number of queries: 2400 |
24 |
Correct |
92 ms |
200 KB |
Correct! Number of queries: 2400 |
25 |
Correct |
89 ms |
200 KB |
Correct! Number of queries: 2400 |
26 |
Correct |
93 ms |
200 KB |
Correct! Number of queries: 2400 |