#include "grader.h"
#include <bits/stdc++.h>
using namespace std;
#define pf printf
vector<int> todo,v;
bool done[260];
int check(int x){ //swap (0,1),(2,3)...(2*x,2*x+1)
for(int i=0;i<=x;++i){
swap(v[todo[2*i]],v[todo[2*i+1]]);
}
int res=query(v);
for(int i=0;i<=x;++i){
swap(v[todo[2*i]],v[todo[2*i+1]]);
}
return res;
}
void solve(int N) {
for(int i=1;i<=N;++i)v.push_back(i);
while(true){
int res=query(v);
if(res==N)return;
if(res==0)break;
random_shuffle(v.begin(),v.end());
}
int pv=0;
while(true){
todo.clear();
for(int i=0;i<N;++i)if(!done[i])todo.push_back(i);
if(todo.size()==0)break;
random_shuffle(todo.begin(),todo.end());
if(check(todo.size()/2-1)==pv)continue;
int lo=0,hi=todo.size()/2-1,mid,res,val;
while(lo<=hi){
mid=(lo+hi)/2;
int tmp=check(mid);
if(tmp==N)return;
if(tmp>pv){
res=mid;
val=tmp;
hi=mid-1;
}
else lo=mid+1;
}
if(val==pv+2){
swap(v[todo[2*res]],v[todo[2*res+1]]);
done[todo[2*res]]=true;
done[todo[2*res+1]]=true;
}
else{
swap(v[todo[2*res]],v[todo[2*res+1]]);
int o=0;
for(int i=0;i<N;++i){
if(!done[i]&&i!=todo[2*res]&&i!=todo[2*res+1]){ o=i;break; }
}
swap(v[todo[2*res]],v[o]);
int tmp=query(v);
if(tmp==N)return;
swap(v[todo[2*res]],v[o]);
if(tmp>pv){
done[todo[2*res+1]]=true;
}
else done[todo[2*res]]=true;
}
pv=query(v);
if(pv==N)return;
}
return;
}
Compilation message
mouse.cpp: In function 'void solve(int)':
mouse.cpp:49:3: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
49 | if(val==pv+2){
| ^~
mouse.cpp:50:32: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
50 | swap(v[todo[2*res]],v[todo[2*res+1]]);
| ~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
200 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
200 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
200 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |