# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
31823 | top34051 | 정렬하기 (IOI15_sorting) | C++14 | 223 ms | 13916 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
int n, s[maxn];
int a[maxn], pos[maxn];
pair<int,int> sw[maxn];
int get(int rec) {
int i,x,cnt;
for(i=0;i<n;i++) a[i] = s[i];
for(i=0;i<n;i++) pos[a[i]] = i;
cnt = 0;
for(i=0;i<n;i++) {
x = pos[i];
if(i!=x) {
pos[a[i]] = x;
swap(a[i], a[x]);
if(rec) sw[cnt] = {a[i],a[x]};
cnt++;
}
}
return cnt;
}
bool check(int x,int S[],int X[],int Y[]) {
int i;
for(i=0;i<n;i++) s[i] = S[i];
for(i=0;i<=x;i++) swap(s[X[i]], s[Y[i]]);
if(get(0)<=x+1) return 1;
else return 0;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
int i,x,now,l,r,mid;
n = N;
for(i=0;i<n;i++) s[i] = S[i];
l = -1; r = N;
while(l<=r) {
mid = (l+r)/2;
if(check(mid,S,X,Y)) now = mid, r = mid-1;
else l = mid+1;
}
check(now,S,X,Y);
get(1);
for(i=0;i<n;i++) s[i] = S[i];
for(i=0;i<n;i++) pos[s[i]] = i;
for(i=0;i<now+1;i++) {
swap(pos[s[X[i]]], pos[s[Y[i]]]);
swap(s[X[i]], s[Y[i]]);
P[i] = pos[sw[i].first];
Q[i] = pos[sw[i].second];
swap(pos[s[P[i]]], pos[s[Q[i]]]);
swap(s[P[i]], s[Q[i]]);
}
return now+1;
}
컴파일 시 표준 에러 (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... |