답안 #921322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
921322 2024-02-03T17:13:54 Z salmon 고대 책들 (IOI17_books) C++14
50 / 100
99 ms 24144 KB
#include <bits/stdc++.h>
using namespace std;

int parent[1100100];
int v[1100100];
bool done[1100100];
int l[1100100];
int r[1100100];

pair<int,int> expand_range(int l2, int r2, int h){
    int l1 = min(l2,h);
    int r1 = max(r2,h);

    while(l1 != l2 || r1 != r2){
        if(l1 != l2){
            l2--;
            l1 = min(l1,l[parent[l2]]);
            r1 = max(r1,r[parent[l2]]);
        }
        else{
            r2++;
            l1 = min(l1,l[parent[r2]]);
            r1 = max(r1,r[parent[r2]]);
        }
    }

    return {l2,r2};
}

long long minimum_walk(vector<int> p, int s) {
    int l1 = s;
    int r1 = s;
    int l2 = s;
    int r2 = s;
    long long int some = 0;

    int N = p.size();

    for(int i = 0; i < N; i++){
        done[i] = false;
    }

    for(int i = 0; i < N; i++){
        if(done[i]) continue;

        l[i] = i;
        r[i] = i;
        parent[i] = i;
        int j = p[i];
        some += abs(i - j);
        while(j != i){
            int temp = j;
            parent[j] = i;
            done[j] = true;
            r[i] = max(r[i],j);
            j = p[j];
            some += abs(temp - j);
        }
    }

    l2 = l[parent[s]];
    r2 = r[parent[s]];

    while(l1 != l2 || r1 != r2){
        if(l1 != l2){
            l1--;
            l2 = min(l2,l[parent[l1]]);
            r2 = max(r2,r[parent[l1]]);
        }
        else{
            r1++;
            l2 = min(l2,l[parent[r1]]);
            r2 = max(r2,r[parent[r1]]);
        }
    }

    int l3l = l1;
    int r3l = r1;

    int l3r = l1;
    int r3r = r1;

    while(l1 != 0 || r1 != N - 1){
        l3l = l1;
        r3l = r1;

        l3r = l1;
        r3r = r1;

        int tcoft = 0;
        int coft = 0;

        while(!(r1 < r3l && l3r < l1)){
            coft += 2;
            tcoft += 2;

            if(l3l > 0){
                pair<int,int> ii = expand_range(l3l,r3l,l3l - 1);
                l3l = ii.first;
                r3l = ii.second;
                tcoft -= 2;
            }

            if(r3r < N - 1){
                pair<int,int> ii = expand_range(l3r,r3r,r3r+1);
                l3r = ii.first;
                r3r = ii.second;
                tcoft -= 2;
            }

            if(!(r1 < r3l && l3r < l1) && l3l == 0 && r3r == N - 1){
                some += tcoft;
                break;
            }
        }

        some += coft;
        l1 = min(l3l,l1);
        l1 = min(l3r,l1);


        r1 = max(r3l,r1);
        r1 = max(r3r,r1);
    }

    for(int i = N - 1; i > s; i--){
        if(p[i] != i) break;
        some -= 2;
    }

    return some;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6488 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6488 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 98 ms 19716 KB Output is correct
31 Correct 97 ms 17672 KB Output is correct
32 Correct 89 ms 24144 KB Output is correct
33 Correct 82 ms 24056 KB Output is correct
34 Correct 82 ms 23888 KB Output is correct
35 Correct 99 ms 23892 KB Output is correct
36 Correct 83 ms 24056 KB Output is correct
37 Correct 75 ms 23888 KB Output is correct
38 Correct 77 ms 24072 KB Output is correct
39 Correct 78 ms 23892 KB Output is correct
40 Correct 82 ms 23892 KB Output is correct
41 Correct 91 ms 23796 KB Output is correct
42 Correct 88 ms 23888 KB Output is correct
43 Correct 78 ms 23888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6488 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3506'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6488 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 98 ms 19716 KB Output is correct
31 Correct 97 ms 17672 KB Output is correct
32 Correct 89 ms 24144 KB Output is correct
33 Correct 82 ms 24056 KB Output is correct
34 Correct 82 ms 23888 KB Output is correct
35 Correct 99 ms 23892 KB Output is correct
36 Correct 83 ms 24056 KB Output is correct
37 Correct 75 ms 23888 KB Output is correct
38 Correct 77 ms 24072 KB Output is correct
39 Correct 78 ms 23892 KB Output is correct
40 Correct 82 ms 23892 KB Output is correct
41 Correct 91 ms 23796 KB Output is correct
42 Correct 88 ms 23888 KB Output is correct
43 Correct 78 ms 23888 KB Output is correct
44 Incorrect 1 ms 6488 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3506'
45 Halted 0 ms 0 KB -