답안 #16668

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
16668 2015-09-04T04:44:29 Z suhgyuho_william 정렬하기 (IOI15_sorting) C++
100 / 100
722 ms 17784 KB
#include "sorting.h"
#include <algorithm>
using namespace std;

int n,R;
int a[200002];
int x[600002],y[600002];
int p[600002],q[600002];
int tested[200002],tester[200002];
int last[200002],where[200002];

bool sorting(){
    int i,cnt;
    int tmp;

    cnt = -1;
    for(i=0; i<n; i++) tested[i] = a[i];
    for(i=0; i<n; i++) tester[i] = a[i];
    for(i=0; i<n; i++) where[tester[i]] = i;
    for(i=0; i<R; i++){
        swap(tested[x[i]],tested[y[i]]);
    }
    for(i=0; i<n; i++) last[tested[i]] = i;

    for(i=0; i<n; i++){
        if(last[i] == i) continue;

        cnt++;
        if(cnt >= R) return false;

        where[tester[x[cnt]]] = y[cnt];
        where[tester[y[cnt]]] = x[cnt];
        swap(tester[x[cnt]],tester[y[cnt]]);

        p[cnt] = where[tested[i]];
        q[cnt] = where[tested[last[i]]];
        //if(p[cnt] > q[cnt]) swap(p[cnt],q[cnt]);
        tmp = last[i];
        last[tested[i]] = last[i];
        last[i] = i;
        swap(tested[i],tested[tmp]);

        where[tester[p[cnt]]] = q[cnt];
        where[tester[q[cnt]]] = p[cnt];
        swap(tester[p[cnt]],tester[q[cnt]]);
    }
    for(i=cnt+1; i<R; i++) p[i] = q[i] = 0;

    return true;
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    int i,s,e;

    s = 0;
    e = M;
    n = N;
    for(i=0; i<N; i++){
        a[i] = S[i];
        x[i] = X[i];
        y[i] = Y[i];
    }
    while(s != e){
        R = (s+e)/2;
        if(sorting()) e = R;
        else s = R+1;
    }
    R = (s+e)/2;

    sorting();
    for(i=0; i<R; i++){
        P[i] = p[i];
        Q[i] = q[i];
    }

	return R;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 3 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 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 3 ms 568 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 4 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 3 ms 568 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 4 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 295 ms 15900 KB Output is correct
16 Correct 434 ms 16092 KB Output is correct
17 Correct 549 ms 17056 KB Output is correct
18 Correct 130 ms 12664 KB Output is correct
19 Correct 420 ms 15224 KB Output is correct
20 Correct 450 ms 15864 KB Output is correct
21 Correct 365 ms 15780 KB Output is correct
22 Correct 297 ms 17272 KB Output is correct
23 Correct 395 ms 17640 KB Output is correct
24 Correct 545 ms 17372 KB Output is correct
25 Correct 722 ms 17184 KB Output is correct
26 Correct 350 ms 15736 KB Output is correct
27 Correct 376 ms 15248 KB Output is correct
28 Correct 609 ms 17144 KB Output is correct
29 Correct 523 ms 16628 KB Output is correct
30 Correct 271 ms 14560 KB Output is correct
31 Correct 478 ms 17148 KB Output is correct
32 Correct 386 ms 17272 KB Output is correct
33 Correct 537 ms 17300 KB Output is correct
34 Correct 418 ms 17400 KB Output is correct
35 Correct 506 ms 15132 KB Output is correct
36 Correct 62 ms 13560 KB Output is correct
37 Correct 669 ms 17784 KB Output is correct
38 Correct 670 ms 17016 KB Output is correct
39 Correct 695 ms 17272 KB Output is correct