Submission #1115053

# Submission time Handle Problem Language Result Execution time Memory
1115053 2024-11-19T23:09:31 Z staszic_ojuz Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
159 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 512 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 504 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 508 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 512 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 504 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 508 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 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 508 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 512 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 504 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 508 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 105 ms 91716 KB Output is correct
19 Correct 46 ms 43184 KB Output is correct
20 Correct 19 ms 16976 KB Output is correct
21 Correct 46 ms 39752 KB Output is correct
22 Correct 64 ms 58604 KB Output is correct
23 Correct 16 ms 13392 KB Output is correct
24 Correct 11 ms 9296 KB Output is correct
25 Correct 16 ms 12892 KB Output is correct
26 Correct 5 ms 3152 KB Output is correct
27 Correct 17 ms 13648 KB Output is correct
28 Correct 10 ms 8272 KB Output is correct
29 Correct 18 ms 14160 KB Output is correct
30 Correct 10 ms 10064 KB Output is correct
31 Correct 13 ms 13052 KB Output is correct
32 Correct 6 ms 4944 KB Output is correct
33 Correct 14 ms 12880 KB Output is correct
34 Correct 4 ms 2896 KB Output is correct
35 Correct 18 ms 12572 KB Output is correct
36 Correct 5 ms 4176 KB Output is correct
37 Correct 20 ms 13648 KB Output is correct
38 Correct 7 ms 5712 KB Output is correct
39 Correct 16 ms 14672 KB Output is correct
40 Correct 8 ms 6904 KB Output is correct
41 Correct 143 ms 125512 KB Output is correct
42 Correct 76 ms 69448 KB Output is correct
43 Correct 125 ms 125576 KB Output is correct
44 Correct 69 ms 68168 KB Output is correct
45 Correct 138 ms 125512 KB Output is correct
46 Correct 77 ms 69444 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 512 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 504 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 508 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 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 508 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 105 ms 91716 KB Output is correct
37 Correct 46 ms 43184 KB Output is correct
38 Correct 19 ms 16976 KB Output is correct
39 Correct 46 ms 39752 KB Output is correct
40 Correct 64 ms 58604 KB Output is correct
41 Correct 16 ms 13392 KB Output is correct
42 Correct 11 ms 9296 KB Output is correct
43 Correct 16 ms 12892 KB Output is correct
44 Correct 5 ms 3152 KB Output is correct
45 Correct 17 ms 13648 KB Output is correct
46 Correct 10 ms 8272 KB Output is correct
47 Correct 18 ms 14160 KB Output is correct
48 Correct 10 ms 10064 KB Output is correct
49 Correct 13 ms 13052 KB Output is correct
50 Correct 6 ms 4944 KB Output is correct
51 Correct 14 ms 12880 KB Output is correct
52 Correct 4 ms 2896 KB Output is correct
53 Correct 18 ms 12572 KB Output is correct
54 Correct 5 ms 4176 KB Output is correct
55 Correct 20 ms 13648 KB Output is correct
56 Correct 7 ms 5712 KB Output is correct
57 Correct 16 ms 14672 KB Output is correct
58 Correct 8 ms 6904 KB Output is correct
59 Correct 143 ms 125512 KB Output is correct
60 Correct 76 ms 69448 KB Output is correct
61 Correct 125 ms 125576 KB Output is correct
62 Correct 69 ms 68168 KB Output is correct
63 Correct 138 ms 125512 KB Output is correct
64 Correct 77 ms 69444 KB Output is correct
65 Correct 112 ms 107760 KB Output is correct
66 Correct 94 ms 94584 KB Output is correct
67 Correct 88 ms 88508 KB Output is correct
68 Correct 77 ms 78664 KB Output is correct
69 Correct 105 ms 106056 KB Output is correct
70 Correct 99 ms 99400 KB Output is correct
71 Correct 108 ms 100936 KB Output is correct
72 Correct 101 ms 102624 KB Output is correct
73 Correct 98 ms 91580 KB Output is correct
74 Correct 82 ms 82772 KB Output is correct
75 Correct 93 ms 96328 KB Output is correct
76 Correct 117 ms 118088 KB Output is correct
77 Correct 117 ms 118088 KB Output is correct
78 Correct 79 ms 80060 KB Output is correct
79 Correct 90 ms 84308 KB Output is correct
80 Correct 114 ms 114760 KB Output is correct
81 Correct 85 ms 85576 KB Output is correct
82 Correct 100 ms 93256 KB Output is correct
83 Correct 133 ms 125512 KB Output is correct
84 Correct 112 ms 99400 KB Output is correct
85 Correct 120 ms 112864 KB Output is correct
86 Correct 121 ms 109460 KB Output is correct
87 Correct 111 ms 96360 KB Output is correct
88 Correct 141 ms 127416 KB Output is correct
89 Correct 137 ms 127452 KB Output is correct
90 Correct 104 ms 98032 KB Output is correct
91 Correct 159 ms 127384 KB Output is correct
92 Correct 133 ms 127560 KB Output is correct
93 Correct 131 ms 123720 KB Output is correct