답안 #369297

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
369297 2021-02-21T07:57:57 Z phathnv Collecting Stamps 3 (JOI20_ho_t3) C++11
100 / 100
107 ms 65132 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 202;
const int INF = 1e9 + 1;

int n, l, x[N], t[N], dist[N][N], dp[N][N][N][2];

void ReadInput(){
    cin >> n >> l;
    for(int i = 1; i <= n; i++)
        cin >> x[i];
    for(int i = 1; i <= n; i++)
        cin >> t[i];
}

void minimize(int &x, const int &y){
    if (x > y)
        x = y;
}

void Solve(){
    x[n + 1] = 0;
    t[n + 1] = 0;

    for(int i = 0; i <= n + 1; i++)
        for(int j = 0; j <= n + 1; j++){
            dist[i][j] = abs(x[i] - x[j]);
            dist[i][j] = min(dist[i][j], l - dist[i][j]);
        }
    for(int i = 0; i <= n + 1; i++)
        for(int j = 0; j <= n + 1; j++)
            for(int k = 0; k <= n + 1; k++)
                for(int c = 0; c < 2; c++)
                    dp[i][j][k][c] = INF;
    int ans = 0;
    dp[0][n + 1][0][0] = dp[0][n + 1][0][1] = 0;
    for(int l = 0; l <= n; l++)
        for(int r = n + 1; r > l + 1; r--)
            for(int k = 0; k < n; k++)
                for(int c = 0; c < 2; c++){
                    if (dp[l][r][k][c] == INF)
                        continue;
                    int pos, val;
                    pos = (c == 0? l : r);
                    val = dp[l][r][k][c] + dist[pos][l + 1];
                    minimize(dp[l + 1][r][k + (t[l + 1] >= val)][0], val);
                    val = dp[l][r][k][c] + dist[pos][r - 1];
                    minimize(dp[l][r - 1][k + (t[r - 1] >= val)][1], val);
                }

    for(int l = 0; l <= n; l++)
        for(int r = n + 1; r > l; r--)
            for(int k = 0; k <= n; k++)
                for(int c = 0; c < 2; c++)
                    ans = max(ans, k * (dp[l][r][k][c] < INF));
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ReadInput();
    Solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 764 KB Output is correct
17 Correct 1 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 764 KB Output is correct
17 Correct 1 ms 748 KB Output is correct
18 Correct 1 ms 876 KB Output is correct
19 Correct 1 ms 620 KB Output is correct
20 Correct 1 ms 748 KB Output is correct
21 Correct 1 ms 876 KB Output is correct
22 Correct 1 ms 620 KB Output is correct
23 Correct 1 ms 876 KB Output is correct
24 Correct 1 ms 748 KB Output is correct
25 Correct 1 ms 876 KB Output is correct
26 Correct 1 ms 876 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 1 ms 1004 KB Output is correct
30 Correct 1 ms 876 KB Output is correct
31 Correct 1 ms 876 KB Output is correct
32 Correct 1 ms 748 KB Output is correct
33 Correct 1 ms 876 KB Output is correct
34 Correct 1 ms 876 KB Output is correct
35 Correct 1 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 764 KB Output is correct
17 Correct 1 ms 748 KB Output is correct
18 Correct 78 ms 52972 KB Output is correct
19 Correct 44 ms 32364 KB Output is correct
20 Correct 19 ms 17528 KB Output is correct
21 Correct 38 ms 30700 KB Output is correct
22 Correct 60 ms 39660 KB Output is correct
23 Correct 17 ms 15084 KB Output is correct
24 Correct 11 ms 11884 KB Output is correct
25 Correct 16 ms 14700 KB Output is correct
26 Correct 5 ms 5868 KB Output is correct
27 Correct 18 ms 15468 KB Output is correct
28 Correct 10 ms 11116 KB Output is correct
29 Correct 17 ms 15596 KB Output is correct
30 Correct 12 ms 12396 KB Output is correct
31 Correct 16 ms 14700 KB Output is correct
32 Correct 7 ms 7916 KB Output is correct
33 Correct 16 ms 14700 KB Output is correct
34 Correct 4 ms 5484 KB Output is correct
35 Correct 15 ms 14444 KB Output is correct
36 Correct 6 ms 7020 KB Output is correct
37 Correct 14 ms 15340 KB Output is correct
38 Correct 8 ms 8556 KB Output is correct
39 Correct 15 ms 15980 KB Output is correct
40 Correct 8 ms 9580 KB Output is correct
41 Correct 107 ms 64876 KB Output is correct
42 Correct 47 ms 44192 KB Output is correct
43 Correct 105 ms 64748 KB Output is correct
44 Correct 44 ms 43628 KB Output is correct
45 Correct 104 ms 64760 KB Output is correct
46 Correct 45 ms 44140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 764 KB Output is correct
17 Correct 1 ms 748 KB Output is correct
18 Correct 1 ms 876 KB Output is correct
19 Correct 1 ms 620 KB Output is correct
20 Correct 1 ms 748 KB Output is correct
21 Correct 1 ms 876 KB Output is correct
22 Correct 1 ms 620 KB Output is correct
23 Correct 1 ms 876 KB Output is correct
24 Correct 1 ms 748 KB Output is correct
25 Correct 1 ms 876 KB Output is correct
26 Correct 1 ms 876 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 1 ms 1004 KB Output is correct
30 Correct 1 ms 876 KB Output is correct
31 Correct 1 ms 876 KB Output is correct
32 Correct 1 ms 748 KB Output is correct
33 Correct 1 ms 876 KB Output is correct
34 Correct 1 ms 876 KB Output is correct
35 Correct 1 ms 876 KB Output is correct
36 Correct 78 ms 52972 KB Output is correct
37 Correct 44 ms 32364 KB Output is correct
38 Correct 19 ms 17528 KB Output is correct
39 Correct 38 ms 30700 KB Output is correct
40 Correct 60 ms 39660 KB Output is correct
41 Correct 17 ms 15084 KB Output is correct
42 Correct 11 ms 11884 KB Output is correct
43 Correct 16 ms 14700 KB Output is correct
44 Correct 5 ms 5868 KB Output is correct
45 Correct 18 ms 15468 KB Output is correct
46 Correct 10 ms 11116 KB Output is correct
47 Correct 17 ms 15596 KB Output is correct
48 Correct 12 ms 12396 KB Output is correct
49 Correct 16 ms 14700 KB Output is correct
50 Correct 7 ms 7916 KB Output is correct
51 Correct 16 ms 14700 KB Output is correct
52 Correct 4 ms 5484 KB Output is correct
53 Correct 15 ms 14444 KB Output is correct
54 Correct 6 ms 7020 KB Output is correct
55 Correct 14 ms 15340 KB Output is correct
56 Correct 8 ms 8556 KB Output is correct
57 Correct 15 ms 15980 KB Output is correct
58 Correct 8 ms 9580 KB Output is correct
59 Correct 107 ms 64876 KB Output is correct
60 Correct 47 ms 44192 KB Output is correct
61 Correct 105 ms 64748 KB Output is correct
62 Correct 44 ms 43628 KB Output is correct
63 Correct 104 ms 64760 KB Output is correct
64 Correct 45 ms 44140 KB Output is correct
65 Correct 72 ms 58988 KB Output is correct
66 Correct 62 ms 54144 KB Output is correct
67 Correct 58 ms 51820 KB Output is correct
68 Correct 53 ms 47980 KB Output is correct
69 Correct 70 ms 58348 KB Output is correct
70 Correct 70 ms 56044 KB Output is correct
71 Correct 64 ms 56556 KB Output is correct
72 Correct 70 ms 57196 KB Output is correct
73 Correct 61 ms 52972 KB Output is correct
74 Correct 60 ms 49644 KB Output is correct
75 Correct 61 ms 54892 KB Output is correct
76 Correct 101 ms 62700 KB Output is correct
77 Correct 72 ms 62700 KB Output is correct
78 Correct 73 ms 48492 KB Output is correct
79 Correct 57 ms 50284 KB Output is correct
80 Correct 102 ms 61552 KB Output is correct
81 Correct 59 ms 50796 KB Output is correct
82 Correct 70 ms 53612 KB Output is correct
83 Correct 75 ms 64748 KB Output is correct
84 Correct 78 ms 55916 KB Output is correct
85 Correct 79 ms 60908 KB Output is correct
86 Correct 83 ms 59500 KB Output is correct
87 Correct 65 ms 54892 KB Output is correct
88 Correct 83 ms 65004 KB Output is correct
89 Correct 78 ms 65132 KB Output is correct
90 Correct 66 ms 55444 KB Output is correct
91 Correct 84 ms 65004 KB Output is correct
92 Correct 77 ms 65004 KB Output is correct
93 Correct 74 ms 64400 KB Output is correct