이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
int R = 0;
for(int i = 0;i < M;i++){
if(is_sorted(S, S+N)) return R;
R++;
swap(S[X[i]], S[Y[i]]);
int opt[N];
for(int j = 0;j<N;j++) opt[j]=j;
for(int j = M-1;j > i;j--) swap(opt[X[j]], opt[Y[j]]);
bool f = false;
for(int j = 0;j < N;j++){
if(S[j] != opt[j]){
f = true;
for(int k = j+1;k < N;k++) {
if(S[k] == opt[j]) {
P[R-1] = j;
Q[R-1] = k;
swap(S[j], S[k]);
break;
}
}
break;
}
}
if(!f) P[R-1] = Q[R-1] = 0;
}
assert(is_sorted(S, S+N));
return R;
}
# | 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... |