답안 #1114806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114806 2024-11-19T16:04:52 Z AdamGS Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
152 ms 127584 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;
}
# 결과 실행 시간 메모리 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 468 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 340 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 1 ms 760 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 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 468 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 340 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 1 ms 760 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 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 2 ms 504 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
# 결과 실행 시간 메모리 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 468 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 340 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 1 ms 760 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 111 ms 91712 KB Output is correct
19 Correct 43 ms 43320 KB Output is correct
20 Correct 22 ms 16912 KB Output is correct
21 Correct 40 ms 39628 KB Output is correct
22 Correct 58 ms 58552 KB Output is correct
23 Correct 14 ms 13392 KB Output is correct
24 Correct 10 ms 9296 KB Output is correct
25 Correct 13 ms 12856 KB Output is correct
26 Correct 6 ms 3152 KB Output is correct
27 Correct 14 ms 13788 KB Output is correct
28 Correct 9 ms 8272 KB Output is correct
29 Correct 16 ms 14308 KB Output is correct
30 Correct 13 ms 10076 KB Output is correct
31 Correct 16 ms 12880 KB Output is correct
32 Correct 7 ms 4944 KB Output is correct
33 Correct 15 ms 12880 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 23 ms 13744 KB Output is correct
38 Correct 6 ms 5712 KB Output is correct
39 Correct 16 ms 14672 KB Output is correct
40 Correct 8 ms 6736 KB Output is correct
41 Correct 140 ms 125512 KB Output is correct
42 Correct 83 ms 69448 KB Output is correct
43 Correct 133 ms 125628 KB Output is correct
44 Correct 75 ms 68168 KB Output is correct
45 Correct 140 ms 125512 KB Output is correct
46 Correct 74 ms 69448 KB Output is correct
# 결과 실행 시간 메모리 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 468 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 340 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 1 ms 760 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 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 2 ms 504 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 111 ms 91712 KB Output is correct
37 Correct 43 ms 43320 KB Output is correct
38 Correct 22 ms 16912 KB Output is correct
39 Correct 40 ms 39628 KB Output is correct
40 Correct 58 ms 58552 KB Output is correct
41 Correct 14 ms 13392 KB Output is correct
42 Correct 10 ms 9296 KB Output is correct
43 Correct 13 ms 12856 KB Output is correct
44 Correct 6 ms 3152 KB Output is correct
45 Correct 14 ms 13788 KB Output is correct
46 Correct 9 ms 8272 KB Output is correct
47 Correct 16 ms 14308 KB Output is correct
48 Correct 13 ms 10076 KB Output is correct
49 Correct 16 ms 12880 KB Output is correct
50 Correct 7 ms 4944 KB Output is correct
51 Correct 15 ms 12880 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 23 ms 13744 KB Output is correct
56 Correct 6 ms 5712 KB Output is correct
57 Correct 16 ms 14672 KB Output is correct
58 Correct 8 ms 6736 KB Output is correct
59 Correct 140 ms 125512 KB Output is correct
60 Correct 83 ms 69448 KB Output is correct
61 Correct 133 ms 125628 KB Output is correct
62 Correct 75 ms 68168 KB Output is correct
63 Correct 140 ms 125512 KB Output is correct
64 Correct 74 ms 69448 KB Output is correct
65 Correct 111 ms 107592 KB Output is correct
66 Correct 104 ms 94776 KB Output is correct
67 Correct 96 ms 88648 KB Output is correct
68 Correct 84 ms 78488 KB Output is correct
69 Correct 126 ms 106056 KB Output is correct
70 Correct 111 ms 99400 KB Output is correct
71 Correct 112 ms 100936 KB Output is correct
72 Correct 106 ms 102816 KB Output is correct
73 Correct 102 ms 91884 KB Output is correct
74 Correct 85 ms 82760 KB Output is correct
75 Correct 108 ms 96376 KB Output is correct
76 Correct 128 ms 118240 KB Output is correct
77 Correct 129 ms 118096 KB Output is correct
78 Correct 107 ms 79944 KB Output is correct
79 Correct 99 ms 84304 KB Output is correct
80 Correct 123 ms 114660 KB Output is correct
81 Correct 94 ms 85632 KB Output is correct
82 Correct 100 ms 93256 KB Output is correct
83 Correct 145 ms 125772 KB Output is correct
84 Correct 107 ms 99400 KB Output is correct
85 Correct 124 ms 112976 KB Output is correct
86 Correct 116 ms 109384 KB Output is correct
87 Correct 111 ms 96328 KB Output is correct
88 Correct 143 ms 127584 KB Output is correct
89 Correct 134 ms 127508 KB Output is correct
90 Correct 107 ms 97784 KB Output is correct
91 Correct 141 ms 127564 KB Output is correct
92 Correct 152 ms 127560 KB Output is correct
93 Correct 137 ms 123720 KB Output is correct