Submission #638780

# Submission time Handle Problem Language Result Execution time Memory
638780 2022-09-07T12:41:28 Z qwerasdfzxcl Ancient Books (IOI17_books) C++17
50 / 100
127 ms 60236 KB
#include "books.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int a[1001000], n;
bool visited[1001000];

ll myabs(ll x){
    if (x<0) return -x;
    return x;
}

ll solve(int l, int r, int s){
    if (l>r) return 0;
    ll ret = 0;

    int mn = s;
    int mx = s;

    int ptl = s, ptr = s;

    while(mn <= ptl || ptr <= mx){
        int j = -1;

        if (mn <= ptl){
            if (visited[ptl]) {--ptl; continue;}
            j = ptl--;
        }
        else{
            if (visited[ptr]) {++ptr; continue;}
            j = ptr++;
        }

        for (;!visited[j];j=a[j]){
            visited[j] = 1;
            ret += myabs(j-a[j]);
            mn = min(mn, j);
            mx = max(mx, j);
        }
    }

    ll ret2 = solve(mx+1, r, mx+1);
    ll ret3 = solve(l, mn-1, mn-1);
    return ret + (ret2 ? ret2+2 : 0) + (ret3 ? ret3+2 : 0);
}

long long minimum_walk(std::vector<int> P, int S) {
    n = P.size();
	for (int i=1;i<=n;i++) a[i] = P[i-1] + 1;

	return solve(1, n, S+1);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 308 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 216 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 308 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 216 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 308 KB Output is correct
30 Correct 127 ms 13216 KB Output is correct
31 Correct 110 ms 13180 KB Output is correct
32 Correct 119 ms 60236 KB Output is correct
33 Correct 108 ms 43260 KB Output is correct
34 Correct 111 ms 43260 KB Output is correct
35 Correct 103 ms 34632 KB Output is correct
36 Correct 102 ms 19412 KB Output is correct
37 Correct 88 ms 13460 KB Output is correct
38 Correct 93 ms 13160 KB Output is correct
39 Correct 100 ms 13188 KB Output is correct
40 Correct 93 ms 13208 KB Output is correct
41 Correct 103 ms 13068 KB Output is correct
42 Correct 100 ms 13216 KB Output is correct
43 Correct 96 ms 13116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3506'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 308 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 216 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 308 KB Output is correct
30 Correct 127 ms 13216 KB Output is correct
31 Correct 110 ms 13180 KB Output is correct
32 Correct 119 ms 60236 KB Output is correct
33 Correct 108 ms 43260 KB Output is correct
34 Correct 111 ms 43260 KB Output is correct
35 Correct 103 ms 34632 KB Output is correct
36 Correct 102 ms 19412 KB Output is correct
37 Correct 88 ms 13460 KB Output is correct
38 Correct 93 ms 13160 KB Output is correct
39 Correct 100 ms 13188 KB Output is correct
40 Correct 93 ms 13208 KB Output is correct
41 Correct 103 ms 13068 KB Output is correct
42 Correct 100 ms 13216 KB Output is correct
43 Correct 96 ms 13116 KB Output is correct
44 Incorrect 1 ms 340 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3506'
45 Halted 0 ms 0 KB -