답안 #46919

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46919 2018-04-24T17:33:45 Z SpaimaCarpatilor 고대 책들 (IOI17_books) C++17
50 / 100
942 ms 110228 KB
#include "books.h"
#include<bits/stdc++.h>

using namespace std;

int nr, N, BG, p[1000009], d[1000009];
set < int > S;
vector < int > v[1000009];

void add (int node, int newD)
{
    if (d[node] != -1) return ;
    d[node] = newD, v[newD].push_back (node), S.erase (node);
    int l = node, r = p[node];
    if (l > r) swap (l, r);
    while (1)
    {
        auto it = S.lower_bound (l);
        if (it == S.end () || *it > r) break;
        add (*it, newD);
    }
}

long long minimum_walk (vector < int > pp, int ss)
{
    N = pp.size (), BG = ss + 1;
    for (int i=1; i<=N; i++)
        p[i] = pp[i - 1] + 1;
    long long ans = 0;
    int lft = 0, rgt = 0;
    for (int i=1; i<=N; i++)
    {
        int curr = i - p[i];
        if (curr < 0) curr = -curr;
        ans += curr;
        if (i != p[i])
        {
            if (lft == 0) lft = i;
            rgt = i;
        }
    }
    if (lft == 0) return ans;
    for (int i=1; i<=N; i++)
        S.insert (i), d[i] = -1;
    add (BG, 0);
    for (int i=0; !v[i].empty (); i++)
        for (auto it : v[i])
        {
            if (it > 1) add (it - 1, i + 1);
            if (it < N) add (it + 1, i + 1);
        }
    int maxi = 0;
    for (int i=lft; i<=rgt; i++)
        maxi = max (maxi, d[i]);
    ans += 2LL * maxi;
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 23800 KB Output is correct
2 Correct 20 ms 23908 KB Output is correct
3 Correct 20 ms 23984 KB Output is correct
4 Correct 20 ms 23984 KB Output is correct
5 Correct 20 ms 23984 KB Output is correct
6 Correct 25 ms 23984 KB Output is correct
7 Correct 20 ms 23984 KB Output is correct
8 Correct 21 ms 23984 KB Output is correct
9 Correct 20 ms 23984 KB Output is correct
10 Correct 20 ms 23984 KB Output is correct
11 Correct 21 ms 23984 KB Output is correct
12 Correct 20 ms 23984 KB Output is correct
13 Correct 21 ms 24044 KB Output is correct
14 Correct 20 ms 24044 KB Output is correct
15 Correct 22 ms 24044 KB Output is correct
16 Correct 21 ms 24044 KB Output is correct
17 Correct 21 ms 24044 KB Output is correct
18 Correct 24 ms 24044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 23800 KB Output is correct
2 Correct 20 ms 23908 KB Output is correct
3 Correct 20 ms 23984 KB Output is correct
4 Correct 20 ms 23984 KB Output is correct
5 Correct 20 ms 23984 KB Output is correct
6 Correct 25 ms 23984 KB Output is correct
7 Correct 20 ms 23984 KB Output is correct
8 Correct 21 ms 23984 KB Output is correct
9 Correct 20 ms 23984 KB Output is correct
10 Correct 20 ms 23984 KB Output is correct
11 Correct 21 ms 23984 KB Output is correct
12 Correct 20 ms 23984 KB Output is correct
13 Correct 21 ms 24044 KB Output is correct
14 Correct 20 ms 24044 KB Output is correct
15 Correct 22 ms 24044 KB Output is correct
16 Correct 21 ms 24044 KB Output is correct
17 Correct 21 ms 24044 KB Output is correct
18 Correct 24 ms 24044 KB Output is correct
19 Correct 21 ms 24172 KB Output is correct
20 Correct 20 ms 24172 KB Output is correct
21 Correct 22 ms 24172 KB Output is correct
22 Correct 20 ms 24172 KB Output is correct
23 Correct 20 ms 24188 KB Output is correct
24 Correct 21 ms 24188 KB Output is correct
25 Correct 21 ms 24188 KB Output is correct
26 Correct 20 ms 24188 KB Output is correct
27 Correct 22 ms 24188 KB Output is correct
28 Correct 22 ms 24188 KB Output is correct
29 Correct 20 ms 24188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 23800 KB Output is correct
2 Correct 20 ms 23908 KB Output is correct
3 Correct 20 ms 23984 KB Output is correct
4 Correct 20 ms 23984 KB Output is correct
5 Correct 20 ms 23984 KB Output is correct
6 Correct 25 ms 23984 KB Output is correct
7 Correct 20 ms 23984 KB Output is correct
8 Correct 21 ms 23984 KB Output is correct
9 Correct 20 ms 23984 KB Output is correct
10 Correct 20 ms 23984 KB Output is correct
11 Correct 21 ms 23984 KB Output is correct
12 Correct 20 ms 23984 KB Output is correct
13 Correct 21 ms 24044 KB Output is correct
14 Correct 20 ms 24044 KB Output is correct
15 Correct 22 ms 24044 KB Output is correct
16 Correct 21 ms 24044 KB Output is correct
17 Correct 21 ms 24044 KB Output is correct
18 Correct 24 ms 24044 KB Output is correct
19 Correct 21 ms 24172 KB Output is correct
20 Correct 20 ms 24172 KB Output is correct
21 Correct 22 ms 24172 KB Output is correct
22 Correct 20 ms 24172 KB Output is correct
23 Correct 20 ms 24188 KB Output is correct
24 Correct 21 ms 24188 KB Output is correct
25 Correct 21 ms 24188 KB Output is correct
26 Correct 20 ms 24188 KB Output is correct
27 Correct 22 ms 24188 KB Output is correct
28 Correct 22 ms 24188 KB Output is correct
29 Correct 20 ms 24188 KB Output is correct
30 Correct 898 ms 110228 KB Output is correct
31 Correct 823 ms 110228 KB Output is correct
32 Correct 167 ms 110228 KB Output is correct
33 Correct 883 ms 110228 KB Output is correct
34 Correct 876 ms 110228 KB Output is correct
35 Correct 924 ms 110228 KB Output is correct
36 Correct 878 ms 110228 KB Output is correct
37 Correct 837 ms 110228 KB Output is correct
38 Correct 835 ms 110228 KB Output is correct
39 Correct 826 ms 110228 KB Output is correct
40 Correct 845 ms 110228 KB Output is correct
41 Correct 860 ms 110228 KB Output is correct
42 Correct 879 ms 110228 KB Output is correct
43 Correct 942 ms 110228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 110228 KB Output is correct
2 Correct 22 ms 110228 KB Output is correct
3 Correct 21 ms 110228 KB Output is correct
4 Incorrect 28 ms 110228 KB 3rd lines differ - on the 1st token, expected: '2094', found: '1592'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 23800 KB Output is correct
2 Correct 20 ms 23908 KB Output is correct
3 Correct 20 ms 23984 KB Output is correct
4 Correct 20 ms 23984 KB Output is correct
5 Correct 20 ms 23984 KB Output is correct
6 Correct 25 ms 23984 KB Output is correct
7 Correct 20 ms 23984 KB Output is correct
8 Correct 21 ms 23984 KB Output is correct
9 Correct 20 ms 23984 KB Output is correct
10 Correct 20 ms 23984 KB Output is correct
11 Correct 21 ms 23984 KB Output is correct
12 Correct 20 ms 23984 KB Output is correct
13 Correct 21 ms 24044 KB Output is correct
14 Correct 20 ms 24044 KB Output is correct
15 Correct 22 ms 24044 KB Output is correct
16 Correct 21 ms 24044 KB Output is correct
17 Correct 21 ms 24044 KB Output is correct
18 Correct 24 ms 24044 KB Output is correct
19 Correct 21 ms 24172 KB Output is correct
20 Correct 20 ms 24172 KB Output is correct
21 Correct 22 ms 24172 KB Output is correct
22 Correct 20 ms 24172 KB Output is correct
23 Correct 20 ms 24188 KB Output is correct
24 Correct 21 ms 24188 KB Output is correct
25 Correct 21 ms 24188 KB Output is correct
26 Correct 20 ms 24188 KB Output is correct
27 Correct 22 ms 24188 KB Output is correct
28 Correct 22 ms 24188 KB Output is correct
29 Correct 20 ms 24188 KB Output is correct
30 Correct 898 ms 110228 KB Output is correct
31 Correct 823 ms 110228 KB Output is correct
32 Correct 167 ms 110228 KB Output is correct
33 Correct 883 ms 110228 KB Output is correct
34 Correct 876 ms 110228 KB Output is correct
35 Correct 924 ms 110228 KB Output is correct
36 Correct 878 ms 110228 KB Output is correct
37 Correct 837 ms 110228 KB Output is correct
38 Correct 835 ms 110228 KB Output is correct
39 Correct 826 ms 110228 KB Output is correct
40 Correct 845 ms 110228 KB Output is correct
41 Correct 860 ms 110228 KB Output is correct
42 Correct 879 ms 110228 KB Output is correct
43 Correct 942 ms 110228 KB Output is correct
44 Correct 22 ms 110228 KB Output is correct
45 Correct 22 ms 110228 KB Output is correct
46 Correct 21 ms 110228 KB Output is correct
47 Incorrect 28 ms 110228 KB 3rd lines differ - on the 1st token, expected: '2094', found: '1592'
48 Halted 0 ms 0 KB -