답안 #1116055

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116055 2024-11-21T08:21:50 Z staszic_ojuz Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
48 ms 142204 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

constexpr ll INF = 1e13 + 7;
constexpr int MAXN = 211;
ll dp[MAXN][MAXN][MAXN][2];

int main()
{
    int n, p;
    cin >> n >> p;
    vector<int> r;
    vector<int> l;
    vector<int> t;
    r.push_back(0);
    r.push_back(0);
    l.push_back(0);
    l.push_back(0);
    t.push_back(0);
    for(int i = 0; i < n; ++i)
    {
        int a;
        cin >> a;
        r.push_back(a);
    }
    for(int i = n+1; i >= 2; --i)
        l.push_back(p-r[i]);
    for(int i = 0; i < n; ++i)
    {
        int a;
        cin >> a;
        t.push_back(a);
    }
    t.push_back(0);
    for(int i = 0; i <= n+1; ++i)
    {
        for(int j = 0; j <= n+1; ++j)
        {
            for(int k = 0; k <= n; ++k)
            {
                dp[i][j][k][0] = INF;
                dp[i][j][k][1] = INF;
            }
        }
    }
    dp[1][1][0][0] = 0;
    dp[1][1][0][1] = 0;
    dp[0][1][0][0] = 0;
    dp[0][1][0][1] = 0;
    dp[1][0][0][0] = 0;
    dp[1][0][0][1] = 0;
    for(int i = 1; i <= n+1; ++i)
    {
        for(int j = 1; j <= n+1; ++j)
        {
            if(j+i > n+2)
                break;
            for(int k = 0; k <= i+j-2; ++k)
            {
                if(k > 0)
                    dp[i][j][k][0] = min(dp[i-1][j][k-1][0] + l[i]-l[i-1], dp[i-1][j][k-1][1] + l[i]+r[j]);
                if(dp[i][j][k][0] > t[n-i+2])
                    dp[i][j][k][0] = min(dp[i-1][j][k][0] + l[i]-l[i-1], dp[i-1][j][k][1] + l[i]+r[j]);
                dp[i][j][k][0] = min(dp[i][j][k][0], INF);

                if(k > 0)
                    dp[i][j][k][1] = min(dp[i][j-1][k-1][1] + r[j]-r[j-1], dp[i][j-1][k-1][0] + l[i]+r[j]);
                if(dp[i][j][k][1] > t[j-1])
                    dp[i][j][k][1] = min(dp[i][j-1][k][1] + r[j]-r[j-1], dp[i][j-1][k][0] + l[i]+r[j]);
                dp[i][j][k][1] = min(dp[i][j][k][1], INF);
            }
        }
    }
    int odp = 0;
    for(int i = 1; i <= n+1; ++i)
    {
        for(int j = 1; j <= n+1; ++j)
        {
            for(int k = 1; k <= n; ++k)
            {
                for(int zj = 0; zj < 2; ++zj)
                {   
                    if(dp[i][j][k][zj] < INF)
                        odp = max(odp, k);
                }
            }
        }
    }
    cout << odp;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4548 KB Output is correct
3 Correct 2 ms 8700 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 2 ms 10592 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 2 ms 8528 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 2 ms 6480 KB Output is correct
15 Correct 2 ms 6480 KB Output is correct
16 Correct 2 ms 10576 KB Output is correct
17 Correct 2 ms 10576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4548 KB Output is correct
3 Correct 2 ms 8700 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 2 ms 10592 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 2 ms 8528 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 2 ms 6480 KB Output is correct
15 Correct 2 ms 6480 KB Output is correct
16 Correct 2 ms 10576 KB Output is correct
17 Correct 2 ms 10576 KB Output is correct
18 Correct 2 ms 12624 KB Output is correct
19 Correct 2 ms 8528 KB Output is correct
20 Correct 2 ms 10828 KB Output is correct
21 Correct 2 ms 12624 KB Output is correct
22 Correct 1 ms 8528 KB Output is correct
23 Correct 2 ms 12624 KB Output is correct
24 Correct 2 ms 10576 KB Output is correct
25 Correct 2 ms 12624 KB Output is correct
26 Correct 2 ms 12732 KB Output is correct
27 Correct 1 ms 6480 KB Output is correct
28 Correct 1 ms 8528 KB Output is correct
29 Correct 2 ms 12624 KB Output is correct
30 Correct 2 ms 12792 KB Output is correct
31 Correct 2 ms 12624 KB Output is correct
32 Correct 2 ms 10576 KB Output is correct
33 Correct 2 ms 12624 KB Output is correct
34 Correct 2 ms 12624 KB Output is correct
35 Correct 2 ms 12624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4548 KB Output is correct
3 Correct 2 ms 8700 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 2 ms 10592 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 2 ms 8528 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 2 ms 6480 KB Output is correct
15 Correct 2 ms 6480 KB Output is correct
16 Correct 2 ms 10576 KB Output is correct
17 Correct 2 ms 10576 KB Output is correct
18 Correct 32 ms 127824 KB Output is correct
19 Correct 23 ms 99068 KB Output is correct
20 Correct 13 ms 72440 KB Output is correct
21 Correct 22 ms 96848 KB Output is correct
22 Correct 27 ms 109368 KB Output is correct
23 Correct 12 ms 66128 KB Output is correct
24 Correct 9 ms 59984 KB Output is correct
25 Correct 10 ms 66252 KB Output is correct
26 Correct 5 ms 41552 KB Output is correct
27 Correct 11 ms 68176 KB Output is correct
28 Correct 9 ms 57984 KB Output is correct
29 Correct 12 ms 68176 KB Output is correct
30 Correct 10 ms 59984 KB Output is correct
31 Correct 11 ms 66128 KB Output is correct
32 Correct 7 ms 47696 KB Output is correct
33 Correct 11 ms 66128 KB Output is correct
34 Correct 7 ms 39504 KB Output is correct
35 Correct 13 ms 66128 KB Output is correct
36 Correct 7 ms 45648 KB Output is correct
37 Correct 12 ms 68256 KB Output is correct
38 Correct 7 ms 49912 KB Output is correct
39 Correct 13 ms 70224 KB Output is correct
40 Correct 8 ms 53840 KB Output is correct
41 Correct 43 ms 142164 KB Output is correct
42 Correct 27 ms 115536 KB Output is correct
43 Correct 40 ms 142172 KB Output is correct
44 Correct 25 ms 115704 KB Output is correct
45 Correct 45 ms 142204 KB Output is correct
46 Correct 27 ms 115504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4548 KB Output is correct
3 Correct 2 ms 8700 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 2 ms 10592 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 2 ms 8528 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 2 ms 6480 KB Output is correct
15 Correct 2 ms 6480 KB Output is correct
16 Correct 2 ms 10576 KB Output is correct
17 Correct 2 ms 10576 KB Output is correct
18 Correct 2 ms 12624 KB Output is correct
19 Correct 2 ms 8528 KB Output is correct
20 Correct 2 ms 10828 KB Output is correct
21 Correct 2 ms 12624 KB Output is correct
22 Correct 1 ms 8528 KB Output is correct
23 Correct 2 ms 12624 KB Output is correct
24 Correct 2 ms 10576 KB Output is correct
25 Correct 2 ms 12624 KB Output is correct
26 Correct 2 ms 12732 KB Output is correct
27 Correct 1 ms 6480 KB Output is correct
28 Correct 1 ms 8528 KB Output is correct
29 Correct 2 ms 12624 KB Output is correct
30 Correct 2 ms 12792 KB Output is correct
31 Correct 2 ms 12624 KB Output is correct
32 Correct 2 ms 10576 KB Output is correct
33 Correct 2 ms 12624 KB Output is correct
34 Correct 2 ms 12624 KB Output is correct
35 Correct 2 ms 12624 KB Output is correct
36 Correct 32 ms 127824 KB Output is correct
37 Correct 23 ms 99068 KB Output is correct
38 Correct 13 ms 72440 KB Output is correct
39 Correct 22 ms 96848 KB Output is correct
40 Correct 27 ms 109368 KB Output is correct
41 Correct 12 ms 66128 KB Output is correct
42 Correct 9 ms 59984 KB Output is correct
43 Correct 10 ms 66252 KB Output is correct
44 Correct 5 ms 41552 KB Output is correct
45 Correct 11 ms 68176 KB Output is correct
46 Correct 9 ms 57984 KB Output is correct
47 Correct 12 ms 68176 KB Output is correct
48 Correct 10 ms 59984 KB Output is correct
49 Correct 11 ms 66128 KB Output is correct
50 Correct 7 ms 47696 KB Output is correct
51 Correct 11 ms 66128 KB Output is correct
52 Correct 7 ms 39504 KB Output is correct
53 Correct 13 ms 66128 KB Output is correct
54 Correct 7 ms 45648 KB Output is correct
55 Correct 12 ms 68256 KB Output is correct
56 Correct 7 ms 49912 KB Output is correct
57 Correct 13 ms 70224 KB Output is correct
58 Correct 8 ms 53840 KB Output is correct
59 Correct 43 ms 142164 KB Output is correct
60 Correct 27 ms 115536 KB Output is correct
61 Correct 40 ms 142172 KB Output is correct
62 Correct 25 ms 115704 KB Output is correct
63 Correct 45 ms 142204 KB Output is correct
64 Correct 27 ms 115504 KB Output is correct
65 Correct 35 ms 133968 KB Output is correct
66 Correct 32 ms 129708 KB Output is correct
67 Correct 30 ms 125776 KB Output is correct
68 Correct 28 ms 121680 KB Output is correct
69 Correct 36 ms 133968 KB Output is correct
70 Correct 34 ms 131920 KB Output is correct
71 Correct 34 ms 131920 KB Output is correct
72 Correct 35 ms 131920 KB Output is correct
73 Correct 31 ms 127824 KB Output is correct
74 Correct 29 ms 123732 KB Output is correct
75 Correct 34 ms 129872 KB Output is correct
76 Correct 42 ms 138064 KB Output is correct
77 Correct 40 ms 138068 KB Output is correct
78 Correct 29 ms 121680 KB Output is correct
79 Correct 30 ms 123728 KB Output is correct
80 Correct 48 ms 137992 KB Output is correct
81 Correct 30 ms 123632 KB Output is correct
82 Correct 31 ms 127824 KB Output is correct
83 Correct 39 ms 142160 KB Output is correct
84 Correct 34 ms 131920 KB Output is correct
85 Correct 36 ms 136016 KB Output is correct
86 Correct 35 ms 136020 KB Output is correct
87 Correct 32 ms 129872 KB Output is correct
88 Correct 38 ms 142160 KB Output is correct
89 Correct 41 ms 142012 KB Output is correct
90 Correct 35 ms 129872 KB Output is correct
91 Correct 39 ms 142160 KB Output is correct
92 Correct 43 ms 142160 KB Output is correct
93 Correct 39 ms 140112 KB Output is correct