이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "sorting.h"
using namespace std;
int n,a[10000],b[10000];
int findSwapPairs(int N1, int S1[], int m, int X[], int Y[], int P[], int Q[]) {
n = N1;
for (int i = 0; i <n ;i++) {
a[i] = S1[i];
}
for (int i = 0; i < m ;i++) {
swap(a[X[i]],a[Y[i]]);
}
for (int i = 0; i < n; i++) {
b[a[i]] = i;
}
vector<pair<int,int> > ans;
for (int i = 0; i < n; i++) {
int j = i;
while (j && a[j] < a[j-1]) {
swap(a[j],a[j-1]);
ans.push_back({a[j],a[j-1]});
j--;
}
}
for (int i = 0; i < n; i++) {
b[S1[i]] = i;
}
// for (int i = 0; i < n; i++) cout << S1[i] <<' ';
for (int i = 0; i < m; i++) ans.push_back({0,0});
for (int i = 0; i < m; i++) {
// swap(S1[X[i]],S1[Y[i]]);
// b[S1[X[i]]] = X[i];
// b[S1[Y[i]]] = Y[i];
swap(S1 [ b[ans[i].first]], S1[ b[ans[i].second ] ]);
// cout << S1[0] <<' '<<S1[1] <<'\n';
P[i] = b[ans[i].first];
Q[i] = b[ans[i].second];
if (ans[i].first >= n || ans[i].second >= n) {
cout <<"no";
exit(0);
}
swap(b[ans[i].first], b[ans[i].second]);
}
return m;
} /*
main(){
srand(time(NULL));
int n,m;
cin >> n ;
int s1[n];
for (int i = 0; i < n;i++) s1[i] = i;
random_shuffle(s1,s1+n);
for (int i = 0; i < n; i++) cout << s1[i] <<' ';
cout <<endl;
// cin >> m;
m = n*n;
int p[m],q[m];
int x[m],y[m];
memset(x,0,sizeof x);
memset(y,0,sizeof y);
// for (int i = 0; i < m;i++) cin >> x[i] >> y[i];
int e = findSwapPairs(n,s1,m,x,y,p,q);
// for (int i = 0; i < n; i++)
// cout << s1[i] <<' ';
cout <<endl;
/// for (int i = 0; i < e; i++)
// cout << p[i] <<' '<<q[i]<<endl;
for (int i = 0; i < n; i++) cout << s1[i] <<' ';
} */
/* 5 6 4 3 2 1 0
0 1
1 2
2 3
3 4
0 1
1 2
*/
# | 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... |