# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
65059 | 2018-08-06T13:55:44 Z | Bodo171 | 정렬하기 (IOI15_sorting) | C++14 | 4 ms | 512 KB |
#include "sorting.h" #include <iostream> const int nmax=200005; using namespace std; int i,n,idx,u; int en[nmax],v[nmax],p[nmax],poz[nmax],a[3*nmax],b[3*nmax],A[3*nmax],B[3*nmax]; bool check(int val) { for(i=0;i<n;i++) poz[v[i]]=i,p[i]=v[i]; for(i=0;i<val;i++) swap(v[a[i]],v[b[i]]); for(i=0;i<n;i++) en[v[i]]=i;//en[i]-pozitia pe care ajunge elementul i; idx=0;u=0; for(i=0;i<val;i++) { while(idx<n&&en[idx]==idx) idx++; if(idx<n) { en[v[idx]]=en[idx];//acum elementul care era pe pozitia noastra ajunge unde ar fi ajuns al noostru v[en[idx]]=v[idx];//facem asta si la nivelul sirului A[u]=poz[idx];B[u]=poz[v[idx]]; ++u; swap(poz[idx],poz[v[idx]]); swap(p[poz[idx]],p[poz[v[idx]]]); idx++; } swap(p[a[i]],p[b[i]]); swap(poz[p[a[i]]],poz[p[b[i]]]); } while(idx<n&&en[idx]==idx) idx++; return (idx==n); } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int ans=M; n=N; for(i=0;i<M;i++) a[i]=X[i],b[i]=Y[i]; for(int p=19;p>=0;p--) { for(i=0;i<N;i++) v[i]=S[i]; if(ans-(1<<p)>=0&&check(ans-(1<<p))) ans-=(1<<p); } for(i=0;i<N;i++) v[i]=S[i]; int okceva=check(ans); for(i=0;i<ans;i++) P[i]=A[i],Q[i]=B[i]; for(i=ans;i<M;i++) P[i]=0,Q[i]=0; return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 3 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 3 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 3 ms | 512 KB | Output is correct |
11 | Correct | 4 ms | 512 KB | Output is correct |
12 | Correct | 3 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Incorrect | 3 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 3 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 3 ms | 512 KB | Output is correct |
11 | Correct | 4 ms | 512 KB | Output is correct |
12 | Correct | 3 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Incorrect | 3 ms | 384 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 512 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 512 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |