답안 #1115050

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115050 2024-11-19T23:07:21 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;
}
# 결과 실행 시간 메모리 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 2 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
# 결과 실행 시간 메모리 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 2 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 456 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 2 ms 512 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 504 KB Output is correct
33 Correct 1 ms 516 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 2 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 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 2 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 100 ms 91640 KB Output is correct
19 Correct 45 ms 43252 KB Output is correct
20 Correct 18 ms 16976 KB Output is correct
21 Correct 44 ms 39620 KB Output is correct
22 Correct 60 ms 58696 KB Output is correct
23 Correct 16 ms 13392 KB Output is correct
24 Correct 11 ms 9168 KB Output is correct
25 Correct 19 ms 12880 KB Output is correct
26 Correct 4 ms 3152 KB Output is correct
27 Correct 20 ms 13836 KB Output is correct
28 Correct 9 ms 8272 KB Output is correct
29 Correct 22 ms 14160 KB Output is correct
30 Correct 16 ms 10076 KB Output is correct
31 Correct 16 ms 12880 KB Output is correct
32 Correct 8 ms 4944 KB Output is correct
33 Correct 15 ms 12880 KB Output is correct
34 Correct 5 ms 3152 KB Output is correct
35 Correct 14 ms 12624 KB Output is correct
36 Correct 5 ms 4176 KB Output is correct
37 Correct 16 ms 13648 KB Output is correct
38 Correct 8 ms 5836 KB Output is correct
39 Correct 17 ms 14672 KB Output is correct
40 Correct 10 ms 6736 KB Output is correct
41 Correct 135 ms 125512 KB Output is correct
42 Correct 79 ms 69448 KB Output is correct
43 Correct 133 ms 125512 KB Output is correct
44 Correct 89 ms 68156 KB Output is correct
45 Correct 133 ms 125540 KB Output is correct
46 Correct 75 ms 69468 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 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 2 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 456 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 2 ms 512 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 504 KB Output is correct
33 Correct 1 ms 516 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 2 ms 336 KB Output is correct
36 Correct 100 ms 91640 KB Output is correct
37 Correct 45 ms 43252 KB Output is correct
38 Correct 18 ms 16976 KB Output is correct
39 Correct 44 ms 39620 KB Output is correct
40 Correct 60 ms 58696 KB Output is correct
41 Correct 16 ms 13392 KB Output is correct
42 Correct 11 ms 9168 KB Output is correct
43 Correct 19 ms 12880 KB Output is correct
44 Correct 4 ms 3152 KB Output is correct
45 Correct 20 ms 13836 KB Output is correct
46 Correct 9 ms 8272 KB Output is correct
47 Correct 22 ms 14160 KB Output is correct
48 Correct 16 ms 10076 KB Output is correct
49 Correct 16 ms 12880 KB Output is correct
50 Correct 8 ms 4944 KB Output is correct
51 Correct 15 ms 12880 KB Output is correct
52 Correct 5 ms 3152 KB Output is correct
53 Correct 14 ms 12624 KB Output is correct
54 Correct 5 ms 4176 KB Output is correct
55 Correct 16 ms 13648 KB Output is correct
56 Correct 8 ms 5836 KB Output is correct
57 Correct 17 ms 14672 KB Output is correct
58 Correct 10 ms 6736 KB Output is correct
59 Correct 135 ms 125512 KB Output is correct
60 Correct 79 ms 69448 KB Output is correct
61 Correct 133 ms 125512 KB Output is correct
62 Correct 89 ms 68156 KB Output is correct
63 Correct 133 ms 125540 KB Output is correct
64 Correct 75 ms 69468 KB Output is correct
65 Correct 115 ms 107808 KB Output is correct
66 Correct 95 ms 94636 KB Output is correct
67 Correct 111 ms 88648 KB Output is correct
68 Correct 98 ms 78668 KB Output is correct
69 Correct 129 ms 106072 KB Output is correct
70 Correct 105 ms 99400 KB Output is correct
71 Correct 106 ms 101192 KB Output is correct
72 Correct 116 ms 102748 KB Output is correct
73 Correct 97 ms 91684 KB Output is correct
74 Correct 86 ms 82760 KB Output is correct
75 Correct 101 ms 96336 KB Output is correct
76 Correct 123 ms 118284 KB Output is correct
77 Correct 123 ms 118088 KB Output is correct
78 Correct 87 ms 79944 KB Output is correct
79 Correct 114 ms 84544 KB Output is correct
80 Correct 119 ms 114504 KB Output is correct
81 Correct 96 ms 85576 KB Output is correct
82 Correct 101 ms 93256 KB Output is correct
83 Correct 134 ms 125576 KB Output is correct
84 Correct 114 ms 99400 KB Output is correct
85 Correct 112 ms 112980 KB Output is correct
86 Correct 112 ms 109384 KB Output is correct
87 Correct 95 ms 96328 KB Output is correct
88 Correct 129 ms 127560 KB Output is correct
89 Correct 151 ms 127388 KB Output is correct
90 Correct 107 ms 97852 KB Output is correct
91 Correct 129 ms 127560 KB Output is correct
92 Correct 136 ms 127528 KB Output is correct
93 Correct 129 ms 123804 KB Output is correct