#include "swaps.h"
#include <bits/stdc++.h>
using namespace std;
bool in[1005];
vector<int> v;
vector<pair<int,int>> asks;
void compute(){
auto res=visit();
reverse(res.begin(),res.end());
for(auto[a,b]:asks){
if(res.back()==0)swap(v[a],v[b]);
res.pop_back();
in[a]=in[b]=false;
}
}
void solve(int N,int V){
for(int i=1;i<=N;++i){
v.push_back(i);
}
for(int p=1;p<=N;p<<=1){
for(int k=p;k>=1;k>>=1){
for(int j=k%p;j<=N-1-k;j+=2*k){
for(int i=0;i<=k-1;++i){
if((i+j)/(2*p)==(i+j+k)/(2*p)&&i+j+k<N){
if(in[v[i+j]]||in[v[i+j+k]])compute();
schedule(v[i+j],v[i+j+k]);
in[v[i+j]]=in[v[i+j+k]]=true;
asks.push_back({v[i+j],v[i+j+k]});
}
}
}
}
}
answer(v);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |