Submission #639890

# Submission time Handle Problem Language Result Execution time Memory
639890 2022-09-12T15:56:41 Z danikoynov Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
176 ms 135268 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 210;
const ll inf = 1e18;

int n;
ll l, x[maxn], t[maxn], dp[maxn][maxn][maxn][2];
void solve()
{
    cin >> n >> l;
    for (int i = 1; i <= n; i ++)
        cin >> x[i];
    for (int i = 1; i <= n; i ++)
        cin >> t[i];
    x[n + 1] = l;

    for (int i = 0; i <= n + 1; i ++)
        for (int j = 0; j <= n + 1; j ++)
            for (int f = 0; f <= n + 1; f ++)
                dp[i][j][f][0] = dp[i][j][f][1] = inf;

    dp[0][n + 1][0][0] = dp[0][n + 1][0][1] = 0;

    ll ans = 0;
    for (int f = 0; f <= n + 1; f ++)
    {
        for (int d = n; d > 0; d --)
        {

            for (int i = 0; i <= n - d + 1; i ++)
            {
                int j = i + d;


                if (i != 0)
                {
                    dp[i][j][f][0] = min(dp[i][j][f][0], dp[i - 1][j][f][0] + x[i] - x[i - 1]);
                    if (f > 0)
                    {
                        ll tp = dp[i - 1][j][f - 1][0] + x[i] - x[i - 1];
                        if (tp <= t[i])
                            dp[i][j][f][0] = min(dp[i][j][f][0], tp);
                    }
                }
                if (j != n + 1)
                {
                    dp[i][j][f][1] = min(dp[i][j][f][1], dp[i][j + 1][f][1] + x[j + 1] - x[j]);
                    if (f > 0)
                    {
                        ll tp = dp[i][j + 1][f - 1][1] + x[j + 1] - x[j];
                        if (tp <= t[j])
                        {
                            dp[i][j][f][1] = min(dp[i][j][f][1], tp);
                        }
                    }
                }

                if (dp[i][j][f][0] + x[i] + l - x[j] < dp[i][j][f][1])
                    dp[i][j][f][1] = dp[i][j][f][0] + x[i] + l - x[j];

                if (dp[i][j][f][1] + x[i] + l - x[j] < dp[i][j][f][0])
                    dp[i][j][f][0] = dp[i][j][f][1] + x[i] + l - x[j];

                if (dp[i][j][f][0] != inf || dp[i][j][f][1] != inf)
                    ans = max(ans, (ll)f);

                ///cout << i << " " << j << " " << f << " " << dp[i][j][f][0] << " " << dp[i][j][f][1] << endl;
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 564 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 948 KB Output is correct
13 Correct 1 ms 944 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 564 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 948 KB Output is correct
13 Correct 1 ms 944 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 952 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 1 ms 1108 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 1200 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
31 Correct 1 ms 1108 KB Output is correct
32 Correct 1 ms 1072 KB Output is correct
33 Correct 1 ms 1236 KB Output is correct
34 Correct 1 ms 1236 KB Output is correct
35 Correct 1 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 564 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 948 KB Output is correct
13 Correct 1 ms 944 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 97 ms 108664 KB Output is correct
19 Correct 48 ms 66128 KB Output is correct
20 Correct 23 ms 35460 KB Output is correct
21 Correct 50 ms 62504 KB Output is correct
22 Correct 65 ms 80844 KB Output is correct
23 Correct 20 ms 30132 KB Output is correct
24 Correct 15 ms 23740 KB Output is correct
25 Correct 19 ms 29524 KB Output is correct
26 Correct 7 ms 11512 KB Output is correct
27 Correct 19 ms 30804 KB Output is correct
28 Correct 13 ms 22100 KB Output is correct
29 Correct 20 ms 31488 KB Output is correct
30 Correct 15 ms 24864 KB Output is correct
31 Correct 19 ms 29556 KB Output is correct
32 Correct 9 ms 15572 KB Output is correct
33 Correct 19 ms 29628 KB Output is correct
34 Correct 6 ms 10676 KB Output is correct
35 Correct 19 ms 29012 KB Output is correct
36 Correct 11 ms 13876 KB Output is correct
37 Correct 21 ms 30864 KB Output is correct
38 Correct 10 ms 16980 KB Output is correct
39 Correct 23 ms 32084 KB Output is correct
40 Correct 12 ms 19000 KB Output is correct
41 Correct 129 ms 133836 KB Output is correct
42 Correct 70 ms 90364 KB Output is correct
43 Correct 130 ms 133964 KB Output is correct
44 Correct 68 ms 89292 KB Output is correct
45 Correct 124 ms 133908 KB Output is correct
46 Correct 73 ms 90360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 564 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 948 KB Output is correct
13 Correct 1 ms 944 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 952 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 1 ms 1108 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 1200 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
31 Correct 1 ms 1108 KB Output is correct
32 Correct 1 ms 1072 KB Output is correct
33 Correct 1 ms 1236 KB Output is correct
34 Correct 1 ms 1236 KB Output is correct
35 Correct 1 ms 1236 KB Output is correct
36 Correct 97 ms 108664 KB Output is correct
37 Correct 48 ms 66128 KB Output is correct
38 Correct 23 ms 35460 KB Output is correct
39 Correct 50 ms 62504 KB Output is correct
40 Correct 65 ms 80844 KB Output is correct
41 Correct 20 ms 30132 KB Output is correct
42 Correct 15 ms 23740 KB Output is correct
43 Correct 19 ms 29524 KB Output is correct
44 Correct 7 ms 11512 KB Output is correct
45 Correct 19 ms 30804 KB Output is correct
46 Correct 13 ms 22100 KB Output is correct
47 Correct 20 ms 31488 KB Output is correct
48 Correct 15 ms 24864 KB Output is correct
49 Correct 19 ms 29556 KB Output is correct
50 Correct 9 ms 15572 KB Output is correct
51 Correct 19 ms 29628 KB Output is correct
52 Correct 6 ms 10676 KB Output is correct
53 Correct 19 ms 29012 KB Output is correct
54 Correct 11 ms 13876 KB Output is correct
55 Correct 21 ms 30864 KB Output is correct
56 Correct 10 ms 16980 KB Output is correct
57 Correct 23 ms 32084 KB Output is correct
58 Correct 12 ms 19000 KB Output is correct
59 Correct 129 ms 133836 KB Output is correct
60 Correct 70 ms 90364 KB Output is correct
61 Correct 130 ms 133964 KB Output is correct
62 Correct 68 ms 89292 KB Output is correct
63 Correct 124 ms 133908 KB Output is correct
64 Correct 73 ms 90360 KB Output is correct
65 Correct 124 ms 120844 KB Output is correct
66 Correct 101 ms 111176 KB Output is correct
67 Correct 103 ms 106396 KB Output is correct
68 Correct 89 ms 98176 KB Output is correct
69 Correct 113 ms 119684 KB Output is correct
70 Correct 100 ms 114716 KB Output is correct
71 Correct 110 ms 115952 KB Output is correct
72 Correct 107 ms 117208 KB Output is correct
73 Correct 90 ms 108620 KB Output is correct
74 Correct 84 ms 101580 KB Output is correct
75 Correct 93 ms 112200 KB Output is correct
76 Correct 119 ms 128588 KB Output is correct
77 Correct 118 ms 128636 KB Output is correct
78 Correct 86 ms 99248 KB Output is correct
79 Correct 89 ms 102772 KB Output is correct
80 Correct 114 ms 126044 KB Output is correct
81 Correct 88 ms 103860 KB Output is correct
82 Correct 93 ms 109752 KB Output is correct
83 Correct 128 ms 133904 KB Output is correct
84 Correct 98 ms 114632 KB Output is correct
85 Correct 110 ms 124684 KB Output is correct
86 Correct 111 ms 122124 KB Output is correct
87 Correct 97 ms 112292 KB Output is correct
88 Correct 130 ms 135136 KB Output is correct
89 Correct 124 ms 135228 KB Output is correct
90 Correct 98 ms 113500 KB Output is correct
91 Correct 176 ms 135180 KB Output is correct
92 Correct 133 ms 135268 KB Output is correct
93 Correct 116 ms 132516 KB Output is correct