This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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[v[a]]=in[v[b]]=false;
}
asks.clear();
}
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({i+j,i+j+k});
}
}
}
}
}
if(!asks.empty())compute();
answer(v);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |