Submission #1115054

# Submission time Handle Problem Language Result Execution time Memory
1115054 2024-11-19T23:14:26 Z staszic_ojuz Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
151 ms 127560 KB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n,l;
    cin>>n>>l;
    vector<long long> tr(n+1);
    vector<long long> tl(n+1);
    vector<long long> rd(n+1);
    vector<long long> ld(n+1);
    rd[0] = 0;
    ld[0] = 0;
    tr[0] = 0;
    tl[0] = 0;
    for(int i = 1;i<n+1;i++)
    {
        cin>>rd[i];
        ld[n-i+1] = l-rd[i];
    }
    for(int i = 1;i<n+1;i++)
    {
        cin>>tr[i];
        tl[n-i+1] = tr[i];
    }
    long long m = 1000000000;
    m *=m;
    long long dp[n+1][n+1][n+1][2];
    dp[0][0][0][0] = 0;
    dp[0][0][0][1] = 0;
    for(int i = 1;i<n+1;i++)
    {
        dp[0][0][i][0] = m;
        dp[0][0][i][1] = m;
    }
    for(int i = 1;i<n+1;i++)
    {
        for(int q = 0;q<n+1;q++)
        {
            dp[i][0][q][0] = m;
            dp[i][0][q][1] = m;
            dp[i][0][q][0] = dp[i-1][0][q][0]-ld[i-1]+ld[i];
            if(q!=0 && dp[i-1][0][q-1][0]+ld[i]-ld[i-1] <= tl[i])
            {
                dp[i][0][q][0] = min(dp[i][0][q][0],dp[i-1][0][q-1][0]+ld[i]-ld[i-1]);
            }
            dp[i][0][q][1] = 2*dp[i][0][q][0];
        }
    }
    for(int j = 1;j<n+1;j++)
    {
        for(int q = 0;q<n+1;q++)
        {
            dp[0][j][q][1] = m;
            dp[0][j][q][0] = m;
            dp[0][j][q][1] = dp[0][j-1][q][1]-rd[j-1]+rd[j];
            if(q!= 0 &&dp[0][j-1][q-1][1]+rd[j]-rd[j-1] <= tr[j])
            {
                dp[0][j][q][1] = min(dp[0][j][q][1],dp[0][j-1][q-1][1]+rd[j]-rd[j-1]);
            }
            dp[0][j][q][0] = 2*dp[0][j][q][1];
        }
    }

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

                dp[i][j][q][0] = m;
                dp[i][j][q][1] = m;
                if(i+j > n) continue;
                if(i!= 0)
                {
                    dp[i][j][q][0] = min(dp[i-1][j][q][0]-ld[i-1]+ld[i],dp[i-1][j][q][1]+rd[j]+ld[i]);
                }
                if(q!=0 && dp[i-1][j][q-1][0]+ld[i]-ld[i-1] <= tl[i])
                {
                    dp[i][j][q][0] = min(dp[i][j][q][0],dp[i-1][j][q-1][0]+ld[i]-ld[i-1]);
                }
                if(q!=0 && dp[i-1][j][q-1][1]+rd[j]+ld[i] <=tl[i])
                {
                    dp[i][j][q][0] = min(dp[i][j][q][0],dp[i-1][j][q-1][1]+ld[i]+rd[j]);
                }
                if(j != 0)
                {
                    dp[i][j][q][1] = min(dp[i][j-1][q][0]+ld[i]+rd[j],dp[i][j-1][q][1]-rd[j-1]+rd[j]);
                }
                if(q!= 0 && dp[i][j-1][q-1][0] + ld[i]+rd[j] <= tr[j])
                {
                    dp[i][j][q][1] = min(dp[i][j][q][1],dp[i][j-1][q-1][0] + ld[i]+rd[j]);
                }
                if(q != 0 && dp[i][j-1][q-1][1] + rd[j]-rd[j-1] <= tr[j])
                {
                    dp[i][j][q][1] = min(dp[i][j][q][1],dp[i][j-1][q-1][1]-rd[j-1]+rd[j]);
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0;i<n+1;i++)
    {
        for(int j = 0;j<n+1;j++)
        {
            for(int q = 0;q<n+1;q++)
            {
                if(dp[i][j][q][0] < m) ans = max(ans,q);
                if(dp[i][j][q][1] < m) ans = max(ans,q);
            }
        }
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 504 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 504 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 102 ms 91720 KB Output is correct
19 Correct 52 ms 43344 KB Output is correct
20 Correct 20 ms 16976 KB Output is correct
21 Correct 44 ms 39764 KB Output is correct
22 Correct 65 ms 58704 KB Output is correct
23 Correct 16 ms 13596 KB Output is correct
24 Correct 11 ms 9296 KB Output is correct
25 Correct 15 ms 12880 KB Output is correct
26 Correct 4 ms 3244 KB Output is correct
27 Correct 17 ms 13648 KB Output is correct
28 Correct 10 ms 8480 KB Output is correct
29 Correct 17 ms 14160 KB Output is correct
30 Correct 11 ms 10064 KB Output is correct
31 Correct 14 ms 12880 KB Output is correct
32 Correct 5 ms 4944 KB Output is correct
33 Correct 14 ms 12992 KB Output is correct
34 Correct 4 ms 2896 KB Output is correct
35 Correct 14 ms 12624 KB Output is correct
36 Correct 5 ms 4176 KB Output is correct
37 Correct 15 ms 13648 KB Output is correct
38 Correct 7 ms 5712 KB Output is correct
39 Correct 17 ms 14672 KB Output is correct
40 Correct 7 ms 6736 KB Output is correct
41 Correct 129 ms 125512 KB Output is correct
42 Correct 78 ms 69452 KB Output is correct
43 Correct 140 ms 125516 KB Output is correct
44 Correct 70 ms 68168 KB Output is correct
45 Correct 130 ms 125512 KB Output is correct
46 Correct 74 ms 69448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 504 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 504 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 102 ms 91720 KB Output is correct
37 Correct 52 ms 43344 KB Output is correct
38 Correct 20 ms 16976 KB Output is correct
39 Correct 44 ms 39764 KB Output is correct
40 Correct 65 ms 58704 KB Output is correct
41 Correct 16 ms 13596 KB Output is correct
42 Correct 11 ms 9296 KB Output is correct
43 Correct 15 ms 12880 KB Output is correct
44 Correct 4 ms 3244 KB Output is correct
45 Correct 17 ms 13648 KB Output is correct
46 Correct 10 ms 8480 KB Output is correct
47 Correct 17 ms 14160 KB Output is correct
48 Correct 11 ms 10064 KB Output is correct
49 Correct 14 ms 12880 KB Output is correct
50 Correct 5 ms 4944 KB Output is correct
51 Correct 14 ms 12992 KB Output is correct
52 Correct 4 ms 2896 KB Output is correct
53 Correct 14 ms 12624 KB Output is correct
54 Correct 5 ms 4176 KB Output is correct
55 Correct 15 ms 13648 KB Output is correct
56 Correct 7 ms 5712 KB Output is correct
57 Correct 17 ms 14672 KB Output is correct
58 Correct 7 ms 6736 KB Output is correct
59 Correct 129 ms 125512 KB Output is correct
60 Correct 78 ms 69452 KB Output is correct
61 Correct 140 ms 125516 KB Output is correct
62 Correct 70 ms 68168 KB Output is correct
63 Correct 130 ms 125512 KB Output is correct
64 Correct 74 ms 69448 KB Output is correct
65 Correct 119 ms 107592 KB Output is correct
66 Correct 102 ms 94792 KB Output is correct
67 Correct 97 ms 88648 KB Output is correct
68 Correct 81 ms 78668 KB Output is correct
69 Correct 120 ms 106068 KB Output is correct
70 Correct 111 ms 99400 KB Output is correct
71 Correct 102 ms 101104 KB Output is correct
72 Correct 112 ms 102728 KB Output is correct
73 Correct 100 ms 91720 KB Output is correct
74 Correct 109 ms 82752 KB Output is correct
75 Correct 103 ms 96328 KB Output is correct
76 Correct 127 ms 118088 KB Output is correct
77 Correct 124 ms 118088 KB Output is correct
78 Correct 100 ms 80080 KB Output is correct
79 Correct 97 ms 84104 KB Output is correct
80 Correct 125 ms 114504 KB Output is correct
81 Correct 94 ms 85576 KB Output is correct
82 Correct 98 ms 93096 KB Output is correct
83 Correct 143 ms 125512 KB Output is correct
84 Correct 112 ms 99408 KB Output is correct
85 Correct 139 ms 112760 KB Output is correct
86 Correct 112 ms 109384 KB Output is correct
87 Correct 103 ms 96340 KB Output is correct
88 Correct 133 ms 127560 KB Output is correct
89 Correct 151 ms 127344 KB Output is correct
90 Correct 100 ms 97872 KB Output is correct
91 Correct 132 ms 127556 KB Output is correct
92 Correct 132 ms 127560 KB Output is correct
93 Correct 132 ms 123704 KB Output is correct