Submission #575433

# Submission time Handle Problem Language Result Execution time Memory
575433 2022-06-10T12:25:18 Z vasilykuzmin22 Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
60 ms 72908 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;

//#define int long long

const int SIZE = 210;
const int INF = 1e9 + 9;
const long long INFL = 1e18 + 9;

int dp[SIZE][SIZE][SIZE][2];

signed main()
{
    for (int i = 0; i < SIZE; ++i)
    {
        for (int j = 0; j < SIZE; ++j)
        {
            for (int k = 0; k < SIZE; ++k)
            {
                dp[i][j][k][0] = INF;
                dp[i][j][k][1] = INF;
            }
        }
    }
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    
    int n, l;
    cin >> n >> l;
    vector <int> x(n + 1);
    x[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        cin >> x[i];
    }
    vector <int> t(n + 1);
    t[0] = -1;
    for (int i = 1; i <= n; ++i)
    {
        cin >> t[i];
    }

    int gans = 0;
    dp[0][0][0][0] = 0;
    for (int ans = 0; ans <= n; ++ans)
    {
        for (int ll = 0; ll <= n; ++ll)
        {
            for (int rr = 0; rr <= n; ++rr)
            {
                if (dp[ans][ll][rr][0] != INF || dp[ans][ll][rr][1] != INF)
                    gans = max(ans, gans);

                if (ll + rr >= n)
                {
                    continue;
                }

                if (dp[ans][ll][rr][0] != INF)
                {
                    int tt = dp[ans][ll][rr][0] + x[ll + 1] - x[ll];
                    if (tt <= t[ll + 1])
                    {
                        dp[ans + 1][ll + 1][rr][0] = min(dp[ans + 1][ll + 1][rr][0], tt);
                    }
                    else 
                    {
                        dp[ans][ll + 1][rr][0] = min(dp[ans][ll + 1][rr][0], tt);
                    }

                    tt = dp[ans][ll][rr][0] + l - (x[n - rr] - x[ll]);
                    if (tt <= t[n - rr])
                    {
                        dp[ans + 1][ll][rr + 1][1] = min(dp[ans + 1][ll][rr + 1][1], tt);
                    }
                    else 
                    {
                        dp[ans][ll][rr + 1][1] = min(dp[ans][ll][rr + 1][1], tt);
                    }
                }

                if (dp[ans][ll][rr][1] != INF)
                {
                    int tt = dp[ans][ll][rr][1] + x[n - rr + 1] - x[n - rr];
                    if (tt <= t[n - rr])
                    {
                        dp[ans + 1][ll][rr + 1][1] = min(dp[ans + 1][ll][rr + 1][1], tt);
                    }
                    else 
                    {
                        dp[ans][ll][rr + 1][1] = min(dp[ans][ll][rr + 1][1], tt);
                    }

                    tt = dp[ans][ll][rr][1] + l - (x[n - rr + 1] - x[ll + 1]);
                    if (tt <= t[ll + 1])
                    {
                        dp[ans + 1][ll + 1][rr][0] = min(dp[ans + 1][ll + 1][rr][0], tt);
                    }
                    else 
                    {
                        dp[ans][ll + 1][rr][0] = min(dp[ans][ll + 1][rr][0], tt);
                    }
                }
            }
        }
    }

    // cerr << dp[5][0][5][1] << '\n';

    cout << gans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 37 ms 72776 KB Output is correct
2 Correct 34 ms 72820 KB Output is correct
3 Correct 40 ms 72688 KB Output is correct
4 Correct 32 ms 72700 KB Output is correct
5 Correct 37 ms 72744 KB Output is correct
6 Correct 37 ms 72756 KB Output is correct
7 Correct 33 ms 72704 KB Output is correct
8 Correct 32 ms 72748 KB Output is correct
9 Correct 34 ms 72788 KB Output is correct
10 Correct 32 ms 72748 KB Output is correct
11 Correct 42 ms 72780 KB Output is correct
12 Correct 34 ms 72788 KB Output is correct
13 Correct 36 ms 72792 KB Output is correct
14 Correct 32 ms 72768 KB Output is correct
15 Correct 32 ms 72796 KB Output is correct
16 Correct 33 ms 72680 KB Output is correct
17 Correct 34 ms 72780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 72776 KB Output is correct
2 Correct 34 ms 72820 KB Output is correct
3 Correct 40 ms 72688 KB Output is correct
4 Correct 32 ms 72700 KB Output is correct
5 Correct 37 ms 72744 KB Output is correct
6 Correct 37 ms 72756 KB Output is correct
7 Correct 33 ms 72704 KB Output is correct
8 Correct 32 ms 72748 KB Output is correct
9 Correct 34 ms 72788 KB Output is correct
10 Correct 32 ms 72748 KB Output is correct
11 Correct 42 ms 72780 KB Output is correct
12 Correct 34 ms 72788 KB Output is correct
13 Correct 36 ms 72792 KB Output is correct
14 Correct 32 ms 72768 KB Output is correct
15 Correct 32 ms 72796 KB Output is correct
16 Correct 33 ms 72680 KB Output is correct
17 Correct 34 ms 72780 KB Output is correct
18 Correct 32 ms 72780 KB Output is correct
19 Correct 37 ms 72716 KB Output is correct
20 Correct 33 ms 72724 KB Output is correct
21 Correct 37 ms 72800 KB Output is correct
22 Correct 34 ms 72752 KB Output is correct
23 Correct 42 ms 72780 KB Output is correct
24 Correct 37 ms 72764 KB Output is correct
25 Correct 32 ms 72908 KB Output is correct
26 Correct 34 ms 72784 KB Output is correct
27 Correct 36 ms 72712 KB Output is correct
28 Correct 35 ms 72728 KB Output is correct
29 Correct 34 ms 72788 KB Output is correct
30 Correct 34 ms 72684 KB Output is correct
31 Correct 35 ms 72788 KB Output is correct
32 Correct 36 ms 72696 KB Output is correct
33 Correct 32 ms 72780 KB Output is correct
34 Correct 36 ms 72760 KB Output is correct
35 Correct 34 ms 72696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 72776 KB Output is correct
2 Correct 34 ms 72820 KB Output is correct
3 Correct 40 ms 72688 KB Output is correct
4 Correct 32 ms 72700 KB Output is correct
5 Correct 37 ms 72744 KB Output is correct
6 Correct 37 ms 72756 KB Output is correct
7 Correct 33 ms 72704 KB Output is correct
8 Correct 32 ms 72748 KB Output is correct
9 Correct 34 ms 72788 KB Output is correct
10 Correct 32 ms 72748 KB Output is correct
11 Correct 42 ms 72780 KB Output is correct
12 Correct 34 ms 72788 KB Output is correct
13 Correct 36 ms 72792 KB Output is correct
14 Correct 32 ms 72768 KB Output is correct
15 Correct 32 ms 72796 KB Output is correct
16 Correct 33 ms 72680 KB Output is correct
17 Correct 34 ms 72780 KB Output is correct
18 Correct 47 ms 72780 KB Output is correct
19 Correct 43 ms 72780 KB Output is correct
20 Correct 36 ms 72800 KB Output is correct
21 Correct 40 ms 72796 KB Output is correct
22 Correct 44 ms 72712 KB Output is correct
23 Correct 36 ms 72724 KB Output is correct
24 Correct 37 ms 72756 KB Output is correct
25 Correct 37 ms 72780 KB Output is correct
26 Correct 33 ms 72756 KB Output is correct
27 Correct 36 ms 72684 KB Output is correct
28 Correct 39 ms 72704 KB Output is correct
29 Correct 38 ms 72780 KB Output is correct
30 Correct 40 ms 72704 KB Output is correct
31 Correct 44 ms 72772 KB Output is correct
32 Correct 35 ms 72728 KB Output is correct
33 Correct 36 ms 72780 KB Output is correct
34 Correct 34 ms 72740 KB Output is correct
35 Correct 37 ms 72732 KB Output is correct
36 Correct 38 ms 72676 KB Output is correct
37 Correct 41 ms 72760 KB Output is correct
38 Correct 35 ms 72748 KB Output is correct
39 Correct 38 ms 72764 KB Output is correct
40 Correct 35 ms 72780 KB Output is correct
41 Correct 51 ms 72788 KB Output is correct
42 Correct 43 ms 72840 KB Output is correct
43 Correct 54 ms 72756 KB Output is correct
44 Correct 42 ms 72780 KB Output is correct
45 Correct 51 ms 72800 KB Output is correct
46 Correct 43 ms 72788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 72776 KB Output is correct
2 Correct 34 ms 72820 KB Output is correct
3 Correct 40 ms 72688 KB Output is correct
4 Correct 32 ms 72700 KB Output is correct
5 Correct 37 ms 72744 KB Output is correct
6 Correct 37 ms 72756 KB Output is correct
7 Correct 33 ms 72704 KB Output is correct
8 Correct 32 ms 72748 KB Output is correct
9 Correct 34 ms 72788 KB Output is correct
10 Correct 32 ms 72748 KB Output is correct
11 Correct 42 ms 72780 KB Output is correct
12 Correct 34 ms 72788 KB Output is correct
13 Correct 36 ms 72792 KB Output is correct
14 Correct 32 ms 72768 KB Output is correct
15 Correct 32 ms 72796 KB Output is correct
16 Correct 33 ms 72680 KB Output is correct
17 Correct 34 ms 72780 KB Output is correct
18 Correct 32 ms 72780 KB Output is correct
19 Correct 37 ms 72716 KB Output is correct
20 Correct 33 ms 72724 KB Output is correct
21 Correct 37 ms 72800 KB Output is correct
22 Correct 34 ms 72752 KB Output is correct
23 Correct 42 ms 72780 KB Output is correct
24 Correct 37 ms 72764 KB Output is correct
25 Correct 32 ms 72908 KB Output is correct
26 Correct 34 ms 72784 KB Output is correct
27 Correct 36 ms 72712 KB Output is correct
28 Correct 35 ms 72728 KB Output is correct
29 Correct 34 ms 72788 KB Output is correct
30 Correct 34 ms 72684 KB Output is correct
31 Correct 35 ms 72788 KB Output is correct
32 Correct 36 ms 72696 KB Output is correct
33 Correct 32 ms 72780 KB Output is correct
34 Correct 36 ms 72760 KB Output is correct
35 Correct 34 ms 72696 KB Output is correct
36 Correct 47 ms 72780 KB Output is correct
37 Correct 43 ms 72780 KB Output is correct
38 Correct 36 ms 72800 KB Output is correct
39 Correct 40 ms 72796 KB Output is correct
40 Correct 44 ms 72712 KB Output is correct
41 Correct 36 ms 72724 KB Output is correct
42 Correct 37 ms 72756 KB Output is correct
43 Correct 37 ms 72780 KB Output is correct
44 Correct 33 ms 72756 KB Output is correct
45 Correct 36 ms 72684 KB Output is correct
46 Correct 39 ms 72704 KB Output is correct
47 Correct 38 ms 72780 KB Output is correct
48 Correct 40 ms 72704 KB Output is correct
49 Correct 44 ms 72772 KB Output is correct
50 Correct 35 ms 72728 KB Output is correct
51 Correct 36 ms 72780 KB Output is correct
52 Correct 34 ms 72740 KB Output is correct
53 Correct 37 ms 72732 KB Output is correct
54 Correct 38 ms 72676 KB Output is correct
55 Correct 41 ms 72760 KB Output is correct
56 Correct 35 ms 72748 KB Output is correct
57 Correct 38 ms 72764 KB Output is correct
58 Correct 35 ms 72780 KB Output is correct
59 Correct 51 ms 72788 KB Output is correct
60 Correct 43 ms 72840 KB Output is correct
61 Correct 54 ms 72756 KB Output is correct
62 Correct 42 ms 72780 KB Output is correct
63 Correct 51 ms 72800 KB Output is correct
64 Correct 43 ms 72788 KB Output is correct
65 Correct 46 ms 72800 KB Output is correct
66 Correct 41 ms 72780 KB Output is correct
67 Correct 50 ms 72780 KB Output is correct
68 Correct 44 ms 72796 KB Output is correct
69 Correct 42 ms 72696 KB Output is correct
70 Correct 44 ms 72752 KB Output is correct
71 Correct 40 ms 72732 KB Output is correct
72 Correct 42 ms 72716 KB Output is correct
73 Correct 39 ms 72776 KB Output is correct
74 Correct 42 ms 72680 KB Output is correct
75 Correct 49 ms 72732 KB Output is correct
76 Correct 48 ms 72800 KB Output is correct
77 Correct 41 ms 72796 KB Output is correct
78 Correct 50 ms 72676 KB Output is correct
79 Correct 47 ms 72800 KB Output is correct
80 Correct 60 ms 72728 KB Output is correct
81 Correct 44 ms 72744 KB Output is correct
82 Correct 48 ms 72800 KB Output is correct
83 Correct 41 ms 72796 KB Output is correct
84 Correct 42 ms 72796 KB Output is correct
85 Correct 40 ms 72800 KB Output is correct
86 Correct 41 ms 72752 KB Output is correct
87 Correct 52 ms 72764 KB Output is correct
88 Correct 56 ms 72800 KB Output is correct
89 Correct 42 ms 72776 KB Output is correct
90 Correct 40 ms 72740 KB Output is correct
91 Correct 48 ms 72780 KB Output is correct
92 Correct 43 ms 72724 KB Output is correct
93 Correct 42 ms 72796 KB Output is correct