# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134319 | Runtime_error_ | 정렬하기 (IOI15_sorting) | C++14 | 108 ms | 17912 KiB |
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 "sorting.h"
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e3+9;
int pos[inf],from[inf],origin[inf],posfrom[inf];
int findSwapPairs(int n, int a[], int m, int x[], int y[], int p[], int q[]){
bool tr = 1;
for(int i=0;i<n;i++){
pos[ a[i] ] = i;
origin[i] = a[i];
if(a[i] != i)
tr = 0;
}
if(tr)
return 0;
for(int i=0;i<m;i++){
int l = 0;
for(int j=0;j<n;j++){
from[j] = j;
a[j] = origin[j];
p[j] = q[j] = 0;
pos[ a[j] ] = j;
posfrom[ from[j] ] = j;
}
for(int j=i;j>=0;j--){
swap(posfrom[ from[ x[j] ] ] , posfrom[ from[ y[j] ] ]);
swap( from[ x[j] ] , from[ y[j] ] );
}
/*for(int j=0;j<n;j++)
cout<<from[j]<<" ";
cout<<endl;*/
for(int j=0;j<=i;j++){
swap(pos[ a[ x[j] ] ] , pos[ a[ y[j] ] ]);
swap(posfrom[ from[ x[j] ] ] , posfrom[ from[ y[j] ] ]);
swap(a[ x[j] ] , a[ y[j] ] );
swap(from[ x[j] ] , from[ y[j] ]);
int idx,idfrom;
while(l<n){
idx = pos[l];
idfrom = posfrom[l];
//for(idx = 0;idx<n && a[idx] != l;idx++);
//for(idfrom = 0;idfrom<n && from[idfrom] != l;idfrom++);
if(idx != idfrom)
break;
l++;
}
swap(pos[ a[ idx ] ] , pos[ a[ idfrom ] ]);
swap(a[idx],a[idfrom]);
//cout<<l<<" "<<idx<<" "<<idfrom<<endl;
p[j] = idx,q[j] = idfrom;
}
//for(int i=0;i<n;i++)
// cout<<a[i]<<" ";
tr = 1;
for(int i=0;i<n;i++)
if(a[i] != i)
tr = 0;
if(tr)
return i+1;
}
}
Compilation message (stderr)
# | 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... |