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<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#include "sorting.h"
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll H = 2e3 + 11;
//ifstream in(".in");
//ofstream out(".out");
int pos[H];
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
int n = N, m = M, cur = 0;
for(int i = 0; i < n; i++){
pos[S[i]] = i;
if(X[i] == 0 && Y[i] == 0)cur++;
}
vector<pi>ans;
if(cur == n){//subtask 1, 2
for(int i = 0; i < n; i++){
if(S[i] == i)continue;
ans.push_back({i, pos[i]});
int x = i, y = S[i];
swap(S[i], S[pos[i]]);
pos[y] = pos[i];
pos[x] = x;
}
int k = 0;
for(auto it : ans){
P[k] = it.ff;
Q[k] = it.ss;
k++;
}
return sz(ans);
}else{//subtask 3
swap(S[0], S[1]); //Ermek first move
pos[S[0]] = 0;
pos[S[1]] = 1;
ans.push_back({pos[0], 1});
int XX = pos[0], YY = 1;
pos[S[1]] = pos[0];
pos[0] = 0;
swap(S[XX], S[YY]);
swap(S[0], S[1]);
//we put 0 on pos 1 then he swaps (0, 1) so we have the form 0, x, ..
ans.push_back({pos[1], 1});
int xx = pos[1], yy = 1;
pos[S[0]] = pos[1];
pos[1] = 1;
swap(S[xx], S[yy]);
swap(S[0], S[1]);
//we put 1 on pos 1 then he swaps (0, 1) so we have the form 1, 0, ..
for(int i = 0; i < n; i++){
cout << S[i] << ' ';
}cout << '\n';
for(int i = 2; i < n; i++){
if(S[i] == i)continue;
ans.push_back({i, pos[i]});
int x = i, y = S[i];
swap(S[i], S[pos[i]]);
pos[y] = pos[i];
pos[x] = x;
//his move
swap(S[0], S[1]);
}
if(S[0] == 0)ans.push_back({0, 0});
int k = 0;
for(auto it : ans){
P[k] = it.ff;
Q[k] = it.ss;
k++;
}
return sz(ans);
}
}
Compilation message (stderr)
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:26:16: warning: unused variable 'm' [-Wunused-variable]
int n = N, m = M, cur = 0;
^
# | 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... |