답안 #638779

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638779 2022-09-07T12:36:02 Z qwerasdfzxcl 고대 책들 (IOI17_books) C++17
50 / 100
148 ms 59896 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 = l;
    int mx = l;

    int ptl = l, ptr = l;

    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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 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 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 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 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 112 ms 12924 KB Output is correct
31 Correct 125 ms 13016 KB Output is correct
32 Correct 148 ms 59896 KB Output is correct
33 Correct 105 ms 43004 KB Output is correct
34 Correct 106 ms 43084 KB Output is correct
35 Correct 102 ms 34288 KB Output is correct
36 Correct 95 ms 19200 KB Output is correct
37 Correct 87 ms 13260 KB Output is correct
38 Correct 99 ms 13040 KB Output is correct
39 Correct 88 ms 12932 KB Output is correct
40 Correct 90 ms 12936 KB Output is correct
41 Correct 99 ms 12936 KB Output is correct
42 Correct 97 ms 12916 KB Output is correct
43 Correct 96 ms 12924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 220 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 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 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 112 ms 12924 KB Output is correct
31 Correct 125 ms 13016 KB Output is correct
32 Correct 148 ms 59896 KB Output is correct
33 Correct 105 ms 43004 KB Output is correct
34 Correct 106 ms 43084 KB Output is correct
35 Correct 102 ms 34288 KB Output is correct
36 Correct 95 ms 19200 KB Output is correct
37 Correct 87 ms 13260 KB Output is correct
38 Correct 99 ms 13040 KB Output is correct
39 Correct 88 ms 12932 KB Output is correct
40 Correct 90 ms 12936 KB Output is correct
41 Correct 99 ms 12936 KB Output is correct
42 Correct 97 ms 12916 KB Output is correct
43 Correct 96 ms 12924 KB Output is correct
44 Incorrect 1 ms 220 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -