답안 #218108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218108 2020-04-01T08:35:51 Z PeppaPig Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
151 ms 131576 KB
#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 205;


int n, l, ans;
int x[N], t[N];
long L[N][N][N], R[N][N][N];

long d(int a, int b) { return min(abs(x[b] - x[a]), l - abs(x[b] - x[a])); }

int main() {
    scanf("%d %d", &n, &l);
    for(int i = 1; i <= n; i++) scanf("%d", x + i); 
    for(int i = 1; i <= n; i++) scanf("%d", t + i); 
    x[n + 1] = l;

    for(int k = 0; k <= n; k++) for(int i = 0; i <= n; i++) for(int j = n + 1; j; j--) {
        if(j <= i || (!i && j == n + 1 && !k)) continue;

        L[k][i][j] = R[k][i][j] = 1e18;
        if(i) L[k][i][j] = min({L[k][i][j], L[k][i-1][j] + d(i-1, i), R[k][i-1][j] + d(j, i)});
        if(j <= n) R[k][i][j] = min({R[k][i][j], L[k][i][j+1] + d(i, j), R[k][i][j+1] + d(j+1, j)});

        if(k) {
            if(i) {
                long T = min(L[k-1][i-1][j] + d(i-1, i), R[k-1][i-1][j] + d(j, i));
                if(T <= t[i]) L[k][i][j] = min(L[k][i][j], T);
            }
            if(j <= n) {
                long T = min(L[k-1][i][j+1] + d(i, j), R[k-1][i][j+1] + d(j+1, j));
                if(T <= t[j]) R[k][i][j] = min(R[k][i][j], T);
            }
        }
        if(L[k][i][j] != 1e18 || R[k][i][j] != 1e18)
            ans = max(ans, k);
    }
    printf("%d\n", ans);

    return 0;
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &l);
     ~~~~~^~~~~~~~~~~~~~~~~
ho_t3.cpp:18:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; i++) scanf("%d", x + i); 
                                 ~~~~~^~~~~~~~~~~~~
ho_t3.cpp:19:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; i++) scanf("%d", t + i); 
                                 ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 1152 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 5 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 1152 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 5 ms 896 KB Output is correct
18 Correct 5 ms 1152 KB Output is correct
19 Correct 5 ms 768 KB Output is correct
20 Correct 5 ms 896 KB Output is correct
21 Correct 5 ms 1152 KB Output is correct
22 Correct 5 ms 896 KB Output is correct
23 Correct 5 ms 1280 KB Output is correct
24 Correct 5 ms 1024 KB Output is correct
25 Correct 5 ms 1152 KB Output is correct
26 Correct 5 ms 1152 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 5 ms 768 KB Output is correct
29 Correct 5 ms 1280 KB Output is correct
30 Correct 5 ms 1280 KB Output is correct
31 Correct 5 ms 1152 KB Output is correct
32 Correct 5 ms 1024 KB Output is correct
33 Correct 5 ms 1280 KB Output is correct
34 Correct 5 ms 1280 KB Output is correct
35 Correct 5 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 1152 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 5 ms 896 KB Output is correct
18 Correct 114 ms 105696 KB Output is correct
19 Correct 68 ms 64248 KB Output is correct
20 Correct 33 ms 34432 KB Output is correct
21 Correct 55 ms 60676 KB Output is correct
22 Correct 75 ms 78644 KB Output is correct
23 Correct 26 ms 29312 KB Output is correct
24 Correct 20 ms 23040 KB Output is correct
25 Correct 25 ms 28672 KB Output is correct
26 Correct 11 ms 11136 KB Output is correct
27 Correct 28 ms 29944 KB Output is correct
28 Correct 19 ms 21376 KB Output is correct
29 Correct 27 ms 30592 KB Output is correct
30 Correct 21 ms 24064 KB Output is correct
31 Correct 25 ms 28672 KB Output is correct
32 Correct 14 ms 15232 KB Output is correct
33 Correct 25 ms 28672 KB Output is correct
34 Correct 10 ms 10368 KB Output is correct
35 Correct 24 ms 28160 KB Output is correct
36 Correct 13 ms 13568 KB Output is correct
37 Correct 26 ms 29952 KB Output is correct
38 Correct 15 ms 16512 KB Output is correct
39 Correct 27 ms 31224 KB Output is correct
40 Correct 17 ms 18432 KB Output is correct
41 Correct 139 ms 130296 KB Output is correct
42 Correct 87 ms 87936 KB Output is correct
43 Correct 139 ms 130296 KB Output is correct
44 Correct 83 ms 86860 KB Output is correct
45 Correct 137 ms 130348 KB Output is correct
46 Correct 89 ms 87928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 1152 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 5 ms 896 KB Output is correct
18 Correct 5 ms 1152 KB Output is correct
19 Correct 5 ms 768 KB Output is correct
20 Correct 5 ms 896 KB Output is correct
21 Correct 5 ms 1152 KB Output is correct
22 Correct 5 ms 896 KB Output is correct
23 Correct 5 ms 1280 KB Output is correct
24 Correct 5 ms 1024 KB Output is correct
25 Correct 5 ms 1152 KB Output is correct
26 Correct 5 ms 1152 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 5 ms 768 KB Output is correct
29 Correct 5 ms 1280 KB Output is correct
30 Correct 5 ms 1280 KB Output is correct
31 Correct 5 ms 1152 KB Output is correct
32 Correct 5 ms 1024 KB Output is correct
33 Correct 5 ms 1280 KB Output is correct
34 Correct 5 ms 1280 KB Output is correct
35 Correct 5 ms 1280 KB Output is correct
36 Correct 114 ms 105696 KB Output is correct
37 Correct 68 ms 64248 KB Output is correct
38 Correct 33 ms 34432 KB Output is correct
39 Correct 55 ms 60676 KB Output is correct
40 Correct 75 ms 78644 KB Output is correct
41 Correct 26 ms 29312 KB Output is correct
42 Correct 20 ms 23040 KB Output is correct
43 Correct 25 ms 28672 KB Output is correct
44 Correct 11 ms 11136 KB Output is correct
45 Correct 28 ms 29944 KB Output is correct
46 Correct 19 ms 21376 KB Output is correct
47 Correct 27 ms 30592 KB Output is correct
48 Correct 21 ms 24064 KB Output is correct
49 Correct 25 ms 28672 KB Output is correct
50 Correct 14 ms 15232 KB Output is correct
51 Correct 25 ms 28672 KB Output is correct
52 Correct 10 ms 10368 KB Output is correct
53 Correct 24 ms 28160 KB Output is correct
54 Correct 13 ms 13568 KB Output is correct
55 Correct 26 ms 29952 KB Output is correct
56 Correct 15 ms 16512 KB Output is correct
57 Correct 27 ms 31224 KB Output is correct
58 Correct 17 ms 18432 KB Output is correct
59 Correct 139 ms 130296 KB Output is correct
60 Correct 87 ms 87936 KB Output is correct
61 Correct 139 ms 130296 KB Output is correct
62 Correct 83 ms 86860 KB Output is correct
63 Correct 137 ms 130348 KB Output is correct
64 Correct 89 ms 87928 KB Output is correct
65 Correct 139 ms 117624 KB Output is correct
66 Correct 119 ms 108092 KB Output is correct
67 Correct 107 ms 103416 KB Output is correct
68 Correct 94 ms 95480 KB Output is correct
69 Correct 143 ms 116472 KB Output is correct
70 Correct 124 ms 111608 KB Output is correct
71 Correct 115 ms 112760 KB Output is correct
72 Correct 120 ms 114016 KB Output is correct
73 Correct 104 ms 105720 KB Output is correct
74 Correct 110 ms 98812 KB Output is correct
75 Correct 113 ms 109176 KB Output is correct
76 Correct 150 ms 125184 KB Output is correct
77 Correct 133 ms 125180 KB Output is correct
78 Correct 99 ms 96640 KB Output is correct
79 Correct 97 ms 99960 KB Output is correct
80 Correct 129 ms 122616 KB Output is correct
81 Correct 99 ms 101112 KB Output is correct
82 Correct 114 ms 106872 KB Output is correct
83 Correct 137 ms 130300 KB Output is correct
84 Correct 114 ms 111608 KB Output is correct
85 Correct 123 ms 121336 KB Output is correct
86 Correct 126 ms 119032 KB Output is correct
87 Correct 109 ms 109176 KB Output is correct
88 Correct 142 ms 131576 KB Output is correct
89 Correct 151 ms 131576 KB Output is correct
90 Correct 115 ms 110400 KB Output is correct
91 Correct 144 ms 131576 KB Output is correct
92 Correct 141 ms 131576 KB Output is correct
93 Correct 133 ms 129016 KB Output is correct