# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134311 | Runtime_error_ | Sorting (IOI15_sorting) | C++14 | 1078 ms | 376 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];
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;
for(int j=i;j>=0;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(a[ x[j] ] , a[ y[j] ] );
swap(from[ x[j] ] , from[ y[j] ]);
int idx,idfrom;
while(l<n){
for(idx = 0;idx<n && a[idx] != l;idx++);
for(idfrom = 0;idfrom<n && from[idfrom] != l;idfrom++);
if(from[idx] != idfrom)
break;
l++;
}
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... |