답안 #196873

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
196873 2020-01-17T11:19:15 Z jovan_b 정렬하기 (IOI15_sorting) C++17
100 / 100
810 ms 32080 KB
#include "sorting.h"
#include <bits/stdc++.h>

using namespace std;

int niz[200005];
int x[600005], y[600005];
int p[600005], q[600005];
int n, m;
int prvo[200005];
int gde[200005];
int who[200005];
int tren[200005];
int trenwho[200005];

bool check(int k){
    for(int i=0; i<n; i++){
        gde[niz[i]] = i;
        who[i] = niz[i];
        tren[niz[i]] = i;
        trenwho[i] = niz[i];
    }
    for(int i=0; i<k; i++){
        swap(who[x[i]], who[y[i]]);
        swap(gde[who[x[i]]], gde[who[y[i]]]);
    }
    for(int i=0; i<m; i++) p[i] = q[i] = 0;
    int g = 0;
    for(int i=0; i<n; i++){
        if(gde[i] != i){
            swap(trenwho[x[g]], trenwho[y[g]]);
            swap(tren[trenwho[x[g]]], tren[trenwho[y[g]]]);
            int u = who[i];
            p[g] = tren[i];
            q[g] = tren[u];
            g++;
            swap(trenwho[tren[i]], trenwho[tren[u]]);
            swap(tren[i], tren[u]);
            swap(who[gde[i]], who[gde[u]]);
            swap(gde[i], gde[u]);
        }
    }
    return g <= k;
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    n = N, m = M;
    for(int i=0; i<n; i++){
        niz[i] = S[i];
    }
    for(int i=0; i<m; i++){
        x[i] = X[i];
        y[i] = Y[i];
    }
    int l = 0, r = m, res = m;
    while(l <= r){
        int mid = (l+r)/2;
        if(check(mid)){
            res = mid;
            r = mid-1;
        }
        else l = mid+1;
    }
    check(res);
    for(int i=0; i<res; i++){
        P[i] = p[i];
        Q[i] = q[i];
    }
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 3 ms 532 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 3 ms 532 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 1 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 5 ms 760 KB Output is correct
22 Correct 4 ms 888 KB Output is correct
23 Correct 4 ms 888 KB Output is correct
24 Correct 4 ms 888 KB Output is correct
25 Correct 4 ms 888 KB Output is correct
26 Correct 4 ms 888 KB Output is correct
27 Correct 4 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 760 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 636 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Correct 4 ms 708 KB Output is correct
12 Correct 4 ms 760 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 3 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 760 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 632 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 4 ms 632 KB Output is correct
9 Correct 4 ms 636 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Correct 4 ms 708 KB Output is correct
12 Correct 4 ms 760 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 3 ms 632 KB Output is correct
15 Correct 471 ms 28412 KB Output is correct
16 Correct 577 ms 29112 KB Output is correct
17 Correct 777 ms 30708 KB Output is correct
18 Correct 145 ms 25976 KB Output is correct
19 Correct 348 ms 29304 KB Output is correct
20 Correct 380 ms 30200 KB Output is correct
21 Correct 367 ms 30072 KB Output is correct
22 Correct 501 ms 26076 KB Output is correct
23 Correct 510 ms 31992 KB Output is correct
24 Correct 724 ms 31336 KB Output is correct
25 Correct 717 ms 30984 KB Output is correct
26 Correct 553 ms 30172 KB Output is correct
27 Correct 506 ms 29312 KB Output is correct
28 Correct 695 ms 31224 KB Output is correct
29 Correct 711 ms 30552 KB Output is correct
30 Correct 437 ms 28664 KB Output is correct
31 Correct 792 ms 31052 KB Output is correct
32 Correct 637 ms 30632 KB Output is correct
33 Correct 810 ms 31196 KB Output is correct
34 Correct 597 ms 31132 KB Output is correct
35 Correct 343 ms 28892 KB Output is correct
36 Correct 103 ms 27712 KB Output is correct
37 Correct 530 ms 32080 KB Output is correct
38 Correct 513 ms 30912 KB Output is correct
39 Correct 513 ms 31064 KB Output is correct