답안 #296775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
296775 2020-09-10T21:23:37 Z peti1234 정렬하기 (IOI15_sorting) C++17
100 / 100
399 ms 16612 KB
#include <bits/stdc++.h>

using namespace std;
const int c=200002;
int lo, hi, mid, st=0, a[c], ia[c], b[c], ib[c], cs1, cs2;
vector<int> e, f;
void acsere() {swap(ia[a[cs1]], ia[a[cs2]]), swap(a[cs1], a[cs2]);}
void bcsere() {swap(ib[b[cs1]], ib[b[cs2]]), swap(b[cs1], b[cs2]);}
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
    lo=-1, hi=n;
    while(hi-lo>1) {
        mid=(hi+lo)/2, st=0;
        for (int i=0; i<n; i++) a[i]=s[i], b[i]=i, ia[s[i]]=i, ib[i]=i;
        e.clear(), f.clear();
        for (int i=mid-1; i>=0; i--) swap(ib[b[x[i]]], ib[b[y[i]]]), swap(b[x[i]], b[y[i]]);
        cs1=x[0], cs2=y[0];
        if (mid) acsere(), bcsere();
        for (int i=0; i<n; i++) {
            if (ia[i]!=ib[i]) {
                cs1=ia[i], cs2=ib[i];
                e.push_back(cs1), f.push_back(cs2);
                acsere();
                st++;
                if (st<mid) {
                cs1=x[st], cs2=y[st];
                acsere(), bcsere();
                }
            }
        }
        while(st<mid) e.push_back(0), f.push_back(0), st++;
        if (st<=mid) {
            hi=mid;
            for (int i=0; i<mid; i++) p[i]=e[i], q[i]=f[i];
        }
        else lo=mid;
    }
    return hi;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:9:39: warning: unused parameter 'm' [-Wunused-parameter]
    9 | int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
      |                                   ~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 416 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 2 ms 640 KB Output is correct
23 Correct 2 ms 640 KB Output is correct
24 Correct 1 ms 640 KB Output is correct
25 Correct 2 ms 640 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 228 ms 14692 KB Output is correct
16 Correct 293 ms 14936 KB Output is correct
17 Correct 382 ms 15556 KB Output is correct
18 Correct 75 ms 11244 KB Output is correct
19 Correct 212 ms 12908 KB Output is correct
20 Correct 254 ms 13844 KB Output is correct
21 Correct 255 ms 13924 KB Output is correct
22 Correct 214 ms 15972 KB Output is correct
23 Correct 235 ms 15972 KB Output is correct
24 Correct 381 ms 15844 KB Output is correct
25 Correct 382 ms 15588 KB Output is correct
26 Correct 248 ms 13688 KB Output is correct
27 Correct 233 ms 13036 KB Output is correct
28 Correct 399 ms 15460 KB Output is correct
29 Correct 394 ms 15336 KB Output is correct
30 Correct 157 ms 13036 KB Output is correct
31 Correct 336 ms 15972 KB Output is correct
32 Correct 261 ms 16388 KB Output is correct
33 Correct 365 ms 16484 KB Output is correct
34 Correct 310 ms 16356 KB Output is correct
35 Correct 261 ms 13420 KB Output is correct
36 Correct 61 ms 12524 KB Output is correct
37 Correct 383 ms 16612 KB Output is correct
38 Correct 356 ms 16228 KB Output is correct
39 Correct 365 ms 16356 KB Output is correct