# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
838374 | AbdelmagedNour | Sorting (IOI15_sorting) | C++17 | 91 ms | 19540 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 <bits/stdc++.h>
using namespace std;
//#include "grader.cpp"
#include "sorting.h"
bool check(int T,int N,int M,int S[],int X[],int Y[],int P[],int Q[]){
vector<vector<int>>nxt(T+1,vector<int>(N));
for(int i=0;i<N;i++)nxt[T][i]=i;
for(int i=T-1;i>=0;i--){
for(int j=0;j<N;j++){
nxt[i][j]=nxt[i+1][j];
}
swap(nxt[i][X[i]],nxt[i][Y[i]]);
}
int a[N];
for(int i=0;i<N;i++)a[i]=S[i];
for(int i=0;i<T;i++){
int j=0;
swap(a[X[i]],a[Y[i]]);
while(j<N&&a[j]==nxt[i+1][j])j++;
if(j==N)P[i]=Q[i]=0;
else P[i]=j,Q[i]=find(nxt[i+1].begin(),nxt[i+1].end(),a[j])-nxt[i+1].begin();
swap(a[P[i]],a[Q[i]]);
}
return is_sorted(a,a+N);
}
int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){
int l=1,r=M,res=1;
if(is_sorted(S,S+N))return 0;
while(l<=r){
int md=(l+r)>>1;
if(check(md,N,M,S,X,Y,P,Q))r=(res=md)-1;
else l=md+1;
}
return res;
}
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... |