# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
672798 | 2022-12-18T07:38:11 Z | jamezzz | 정렬하기 (IOI15_sorting) | C++17 | 2 ms | 468 KB |
#include "sorting.h" #include <bits/stdc++.h> using namespace std; #define maxn 200005 int a[maxn],pos[maxn],plate[maxn]; int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){ int lo=0,hi=M,mid,res=0; while(lo<=hi){ mid=(lo+hi)>>1; //printf("mid: %d\n",mid); for(int i=0;i<N;++i)plate[i]=i,a[i]=S[i]; for(int i=mid-1;i>=0;--i)swap(plate[X[i]],plate[Y[i]]); for(int i=0;i<N;++i)pos[plate[i]]=i; //printf("pos: ");for(int i=0;i<N;++i)printf("%d ",pos[i]);printf("\n"); //printf("plate: ");for(int i=0;i<N;++i)printf("%d ",plate[i]);printf("\n"); vector<pair<int,int>> v; for(int i=0;i<N;++i){ while(plate[i]!=a[i]){ v.push_back({plate[i],a[i]}); //printf("swap: %d %d\n",a[i],plate[i]); swap(a[i],a[pos[a[i]]]); } } if(v.size()<=mid){ for(int i=0;i<v.size();++i){ auto[x,y]=v[i]; P[i]=pos[x],Q[i]=pos[y]; int a=plate[X[i]],b=plate[Y[i]]; swap(pos[a],pos[b]); swap(plate[X[i]],plate[Y[i]]); } for(int i=v.size();i<M;++i){ P[i]=Q[i]=0; if(i<mid){ int a=plate[X[i]],b=plate[Y[i]]; swap(pos[a],pos[b]); swap(plate[X[i]],plate[Y[i]]); } } hi=mid-1; res=mid; for(int i=0;i<N;++i){ assert(plate[i]==i&&pos[i]==i); } } else lo=mid+1; } return res; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 0 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Incorrect | 0 ms | 212 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |