Submission #924575

# Submission time Handle Problem Language Result Execution time Memory
924575 2024-02-09T08:28:18 Z qwe1rt1yuiop1 Collecting Stamps 3 (JOI20_ho_t3) C++14
15 / 100
2000 ms 323004 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
using pii = pair<int, int>;

int n, l;

vector<int> x, t;

int dis(int a, int b)
{
    assert(0 <= a && 0 <= b && a <= n && b <= n);
    return min(min(abs(x[a] - x[b]), x[a] + l - x[b]), l - x[a] + x[b]);
}

void solve()
{
    cin >> n >> l;
    x.assign(n + 1, 0), t.assign(n + 1, -1);
    for (int i = 1; i <= n; ++i)
        cin >> x[i];
    for (int i = 1; i <= n; ++i)
        cin >> t[i];

    vector<vector<vector<vector<int>>>> dp(n + 1, vector<vector<vector<int>>>(n + 1, vector<vector<int>>(n + 1, vector<int>(2, LONG_LONG_MAX))));
    dp[0][0][0][0] = dp[0][0][0][1] = 0;

    for (int a = 0; a < 1000; ++a)
    for (int i = 0; i < n; ++i)
        for (int j = 0; j <= n; ++j)
            for (int k = 0; k <= n; ++k)
            {
                if (dp[i][j][k][0] != LONG_LONG_MAX)
                {
                    if ((j + n) % (n + 1) != k)
                    {
                        dp[i][(j + n) % (n + 1)][k][0] = min(dp[i][(j + n) % (n + 1)][k][0], dp[i][j][k][0] + dis(j, (j + n) % (n + 1)));
                        if (dp[i][j][k][0] + dis(j, (j + n) % (n + 1)) <= t[(j + n) % (n + 1)])
                            dp[i + 1][(j + n) % (n + 1)][k][0] = min(dp[i + 1][(j + n) % (n + 1)][k][0], dp[i][j][k][0] + dis(j, (j + n) % (n + 1)));
                    }
                    if (j != (k + 1) % (n + 1))
                    {
                        dp[i][j][(k + 1) % (n + 1)][1] = min(dp[i][j][(k + 1) % (n + 1)][1], dp[i][j][k][0] + dis(j, (k + 1) % (n + 1)));
                        if (dp[i][j][k][0] + dis(j, (k + 1) % (n + 1)) <= t[(k + 1) % (n + 1)])
                            dp[i + 1][j][(k + 1) % (n + 1)][1] = min(dp[i + 1][j][(k + 1) % (n + 1)][1], dp[i][j][k][0] + dis(j, (k + 1) % (n + 1)));
                    }
                }
                if (dp[i][j][k][1] != LONG_LONG_MAX)
                {
                    if ((j + n) % (n + 1) != k)
                    {
                        dp[i][(j + n) % (n + 1)][k][0] = min(dp[i][(j + n) % (n + 1)][k][0], dp[i][j][k][1] + dis(k, (j + n) % (n + 1)));
                        if (dp[i][j][k][1] + dis(k, (j + n) % (n + 1)) <= t[(j + n) % (n + 1)])
                            dp[i + 1][(j + n) % (n + 1)][k][0] = min(dp[i + 1][(j + n) % (n + 1)][k][0], dp[i][j][k][1] + dis(k, (j + n) % (n + 1)));
                    }
                    if (j != (k + 1) % (n + 1))
                    {
                        dp[i][j][(k + 1) % (n + 1)][1] = min(dp[i][j][(k + 1) % (n + 1)][1], dp[i][j][k][1] + dis(k, (k + 1) % (n + 1)));
                        if (dp[i][j][k][1] + dis(k, (k + 1) % (n + 1)) <= t[(k + 1) % (n + 1)])
                            dp[i + 1][j][(k + 1) % (n + 1)][1] = min(dp[i + 1][j][(k + 1) % (n + 1)][1], dp[i][j][k][1] + dis(k, (k + 1) % (n + 1)));
                    }
                }
            }

    int ans = 0;
    for (int i = 0; i <= n; ++i)
        for (int j = 0; j <= n; ++j)
            for (int k = 0; k <= n; ++k)
                for (int l = 0; l < 2; ++l)
                    if (dp[i][j][k][l] != LONG_LONG_MAX)
                        ans = max(ans, i);
    cout << ans << '\n';
}

/*
6 25
3 4 7 17 21 23
11 7 17 10 8 10

5 20
4 5 8 13 17
18 23 15 7 10

4 19
3 7 12 14
2 0 5 4

10 87
9 23 33 38 42 44 45 62 67 78
15 91 7 27 31 53 12 91 89 46

 */

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 6 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 15 ms 588 KB Output is correct
7 Correct 4 ms 500 KB Output is correct
8 Correct 10 ms 540 KB Output is correct
9 Correct 20 ms 584 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 22 ms 348 KB Output is correct
13 Correct 20 ms 344 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 23 ms 348 KB Output is correct
17 Correct 26 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 6 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 15 ms 588 KB Output is correct
7 Correct 4 ms 500 KB Output is correct
8 Correct 10 ms 540 KB Output is correct
9 Correct 20 ms 584 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 22 ms 348 KB Output is correct
13 Correct 20 ms 344 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 23 ms 348 KB Output is correct
17 Correct 26 ms 348 KB Output is correct
18 Correct 30 ms 604 KB Output is correct
19 Correct 7 ms 348 KB Output is correct
20 Correct 17 ms 344 KB Output is correct
21 Correct 27 ms 604 KB Output is correct
22 Correct 9 ms 344 KB Output is correct
23 Correct 44 ms 600 KB Output is correct
24 Correct 15 ms 600 KB Output is correct
25 Correct 36 ms 848 KB Output is correct
26 Correct 23 ms 604 KB Output is correct
27 Correct 7 ms 348 KB Output is correct
28 Correct 8 ms 348 KB Output is correct
29 Correct 53 ms 604 KB Output is correct
30 Correct 43 ms 688 KB Output is correct
31 Correct 8 ms 600 KB Output is correct
32 Correct 7 ms 604 KB Output is correct
33 Correct 53 ms 684 KB Output is correct
34 Correct 45 ms 604 KB Output is correct
35 Correct 44 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 6 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 15 ms 588 KB Output is correct
7 Correct 4 ms 500 KB Output is correct
8 Correct 10 ms 540 KB Output is correct
9 Correct 20 ms 584 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 22 ms 348 KB Output is correct
13 Correct 20 ms 344 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 23 ms 348 KB Output is correct
17 Correct 26 ms 348 KB Output is correct
18 Execution timed out 2044 ms 323004 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 6 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 15 ms 588 KB Output is correct
7 Correct 4 ms 500 KB Output is correct
8 Correct 10 ms 540 KB Output is correct
9 Correct 20 ms 584 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 22 ms 348 KB Output is correct
13 Correct 20 ms 344 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 23 ms 348 KB Output is correct
17 Correct 26 ms 348 KB Output is correct
18 Correct 30 ms 604 KB Output is correct
19 Correct 7 ms 348 KB Output is correct
20 Correct 17 ms 344 KB Output is correct
21 Correct 27 ms 604 KB Output is correct
22 Correct 9 ms 344 KB Output is correct
23 Correct 44 ms 600 KB Output is correct
24 Correct 15 ms 600 KB Output is correct
25 Correct 36 ms 848 KB Output is correct
26 Correct 23 ms 604 KB Output is correct
27 Correct 7 ms 348 KB Output is correct
28 Correct 8 ms 348 KB Output is correct
29 Correct 53 ms 604 KB Output is correct
30 Correct 43 ms 688 KB Output is correct
31 Correct 8 ms 600 KB Output is correct
32 Correct 7 ms 604 KB Output is correct
33 Correct 53 ms 684 KB Output is correct
34 Correct 45 ms 604 KB Output is correct
35 Correct 44 ms 600 KB Output is correct
36 Execution timed out 2044 ms 323004 KB Time limit exceeded
37 Halted 0 ms 0 KB -