This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//
// --- Sample implementation for the task swaps ---
//
// To compile this program with the sample grader, place:
// swaps.h swaps_sample.cpp sample_grader.cpp
// in a single folder and run:
// g++ swaps_sample.cpp sample_grader.cpp
// in this folder.
//
#include "swaps.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using pi = pair<int,int>;
void solve(int N, int V) {
vector<vector<int>> lw(N,vector<int>(N,-1));
for(int st = 0; st < N; st ++) {
vector<int> res;
int idx;
vector<pi> ss;
for(int l = 0; l < N/2; l ++) {
int i = (st + l)%N;
int j = (st + N - 1 - l)%N;
if(i > j) { swap(i,j); }
ss.push_back({i,j});
}
for(pi p : ss) {
schedule(p.f+1,p.s+1);
}
res = visit();
idx = 0;
for(pi p : ss) {
lw[p.f][p.s] = res[idx];
lw[p.f][p.s] = 1 - res[idx];
idx ++;
}
ss.clear();
for(int l = 0; l < (N-1)/2; l ++) {
int i = (st + l)%N;
int j = (st + N - 2 - l)%N;
if(i > j) { swap(i,j); }
ss.push_back({i,j});
}
for(pi p : ss) {
schedule(p.f+1,p.s+1);
}
res = visit();
idx = 0;
for(pi p : ss) {
lw[p.f][p.s] = res[idx];
lw[p.f][p.s] = 1 - res[idx];
idx ++;
}
}
vector<int> res(N);
for(int i = 0; i < N; i ++) {
res[i] = N-i-1;
}
// for(int it = 0; it < 2*N; it ++) {
// for(int i = 1; i < N; i ++) {
// if(lw[res[i-1]][res[i]]) {
// swap(res[i-1],res[i]);
// }
// }
// }
for(int &r : res) { r ++; }
answer(res);
}
/*
g++ swaps.cpp grader.cpp -o g.exe && g.exe
5 1000
2 1 5 3 4
1
1
*/
/*
4 1 5 3 4
*/
# | 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... |