Submission #245428

# Submission time Handle Problem Language Result Execution time Memory
245428 2020-07-06T11:55:53 Z egekabas Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
123 ms 134648 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<int, int>  pii;
typedef pair<ld, ld>  pld;
const ll inf = 1e18+9;
ll n, l;
ll a[209];
ll b[209];
ll dp[209][209][209][2];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    //freopen("in.txt", "r", stdin);                                                                                             
    //freopen("out.txt", "w", stdout);
    
    cin >> n >> l;
    for(ll i = 1; i <= n; ++i)
        cin >> a[i];
    for(ll i = 1; i <= n; ++i)
        cin >> b[i];
    for(ll i1 = 0; i1 <= n+1; ++i1)
        for(ll i2 = 0; i2 <= n+1; ++i2)
            for(ll i3 = 0; i3 <= n+1; ++i3)
                for(ll i4 = 0; i4 < 2; ++i4)
                    dp[i1][i2][i3][i4] = inf;
    a[n+1] = l;
    dp[0][n+1][0][0] = dp[0][n+1][0][1] = 0;
    ll ans = 0;
    for(ll x1 = 0; x1 <= n+1; ++x1)
        for(ll x2 = n+1; x2 >= 0; --x2)
            for(ll get = 0; get <= n+1; ++get)
                for(ll st = 0; st < 2; ++st){
                    if(dp[x1][x2][get][st] == inf) continue;
                    ans = max(ans, get);
                    if(x1+1 >= x2) continue;
                    if(st == 0){
                        ll t1 = dp[x1][x2][get][st] + a[x1+1] - a[x1];
                        if(t1 <= b[x1+1])
                            dp[x1+1][x2][get+1][st] = min(dp[x1+1][x2][get+1][st], t1);
                        else
                            dp[x1+1][x2][get][st] = min(dp[x1+1][x2][get][st], t1);
                        
                        ll t2 = dp[x1][x2][get][st] + a[x1] + l-a[x2-1];
                        if(t2 <= b[x2-1])
                            dp[x1][x2-1][get+1][st^1] = min(dp[x1][x2-1][get+1][st^1], t2);
                        else
                            dp[x1][x2-1][get][st^1] = min(dp[x1][x2-1][get][st^1], t2);
                    }
                    else{
                        ll t1 = dp[x1][x2][get][st] + a[x1+1] + l-a[x2];
                        if(t1 <= b[x1+1])
                            dp[x1+1][x2][get+1][st^1] = min(dp[x1+1][x2][get+1][st^1], t1);
                        else
                            dp[x1+1][x2][get][st^1] = min(dp[x1+1][x2][get][st^1], t1);
                        
                        ll t2 = dp[x1][x2][get][st] + a[x2] - a[x2-1];
                        if(t2 <= b[x2-1])
                            dp[x1][x2-1][get+1][st] = min(dp[x1][x2-1][get+1][st], t2);
                        else
                            dp[x1][x2-1][get][st] = min(dp[x1][x2-1][get][st], t2);
                    }
                }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 896 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 1016 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 5 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 896 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 1016 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 5 ms 1024 KB Output is correct
18 Correct 6 ms 1280 KB Output is correct
19 Correct 5 ms 896 KB Output is correct
20 Correct 5 ms 1024 KB Output is correct
21 Correct 5 ms 1152 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 5 ms 1280 KB Output is correct
24 Correct 7 ms 1152 KB Output is correct
25 Correct 5 ms 1152 KB Output is correct
26 Correct 5 ms 1024 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 5 ms 896 KB Output is correct
29 Correct 5 ms 1280 KB Output is correct
30 Correct 5 ms 1280 KB Output is correct
31 Correct 5 ms 1152 KB Output is correct
32 Correct 5 ms 1152 KB Output is correct
33 Correct 5 ms 1280 KB Output is correct
34 Correct 5 ms 1280 KB Output is correct
35 Correct 5 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 896 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 1016 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 5 ms 1024 KB Output is correct
18 Correct 86 ms 108152 KB Output is correct
19 Correct 53 ms 65912 KB Output is correct
20 Correct 28 ms 35328 KB Output is correct
21 Correct 49 ms 62144 KB Output is correct
22 Correct 68 ms 80516 KB Output is correct
23 Correct 24 ms 30080 KB Output is correct
24 Correct 23 ms 23680 KB Output is correct
25 Correct 32 ms 29568 KB Output is correct
26 Correct 11 ms 11520 KB Output is correct
27 Correct 24 ms 30712 KB Output is correct
28 Correct 17 ms 22016 KB Output is correct
29 Correct 29 ms 31488 KB Output is correct
30 Correct 20 ms 24832 KB Output is correct
31 Correct 23 ms 29568 KB Output is correct
32 Correct 14 ms 15744 KB Output is correct
33 Correct 30 ms 29568 KB Output is correct
34 Correct 11 ms 10752 KB Output is correct
35 Correct 30 ms 28920 KB Output is correct
36 Correct 16 ms 13952 KB Output is correct
37 Correct 29 ms 30848 KB Output is correct
38 Correct 17 ms 17024 KB Output is correct
39 Correct 27 ms 32128 KB Output is correct
40 Correct 20 ms 18976 KB Output is correct
41 Correct 120 ms 133396 KB Output is correct
42 Correct 71 ms 90060 KB Output is correct
43 Correct 109 ms 133368 KB Output is correct
44 Correct 62 ms 88952 KB Output is correct
45 Correct 112 ms 133268 KB Output is correct
46 Correct 88 ms 89976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 896 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 1016 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 5 ms 1024 KB Output is correct
18 Correct 6 ms 1280 KB Output is correct
19 Correct 5 ms 896 KB Output is correct
20 Correct 5 ms 1024 KB Output is correct
21 Correct 5 ms 1152 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 5 ms 1280 KB Output is correct
24 Correct 7 ms 1152 KB Output is correct
25 Correct 5 ms 1152 KB Output is correct
26 Correct 5 ms 1024 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 5 ms 896 KB Output is correct
29 Correct 5 ms 1280 KB Output is correct
30 Correct 5 ms 1280 KB Output is correct
31 Correct 5 ms 1152 KB Output is correct
32 Correct 5 ms 1152 KB Output is correct
33 Correct 5 ms 1280 KB Output is correct
34 Correct 5 ms 1280 KB Output is correct
35 Correct 5 ms 1280 KB Output is correct
36 Correct 86 ms 108152 KB Output is correct
37 Correct 53 ms 65912 KB Output is correct
38 Correct 28 ms 35328 KB Output is correct
39 Correct 49 ms 62144 KB Output is correct
40 Correct 68 ms 80516 KB Output is correct
41 Correct 24 ms 30080 KB Output is correct
42 Correct 23 ms 23680 KB Output is correct
43 Correct 32 ms 29568 KB Output is correct
44 Correct 11 ms 11520 KB Output is correct
45 Correct 24 ms 30712 KB Output is correct
46 Correct 17 ms 22016 KB Output is correct
47 Correct 29 ms 31488 KB Output is correct
48 Correct 20 ms 24832 KB Output is correct
49 Correct 23 ms 29568 KB Output is correct
50 Correct 14 ms 15744 KB Output is correct
51 Correct 30 ms 29568 KB Output is correct
52 Correct 11 ms 10752 KB Output is correct
53 Correct 30 ms 28920 KB Output is correct
54 Correct 16 ms 13952 KB Output is correct
55 Correct 29 ms 30848 KB Output is correct
56 Correct 17 ms 17024 KB Output is correct
57 Correct 27 ms 32128 KB Output is correct
58 Correct 20 ms 18976 KB Output is correct
59 Correct 120 ms 133396 KB Output is correct
60 Correct 71 ms 90060 KB Output is correct
61 Correct 109 ms 133368 KB Output is correct
62 Correct 62 ms 88952 KB Output is correct
63 Correct 112 ms 133268 KB Output is correct
64 Correct 88 ms 89976 KB Output is correct
65 Correct 114 ms 120440 KB Output is correct
66 Correct 90 ms 110656 KB Output is correct
67 Correct 83 ms 105848 KB Output is correct
68 Correct 76 ms 97784 KB Output is correct
69 Correct 108 ms 119160 KB Output is correct
70 Correct 94 ms 114180 KB Output is correct
71 Correct 105 ms 115536 KB Output is correct
72 Correct 100 ms 116728 KB Output is correct
73 Correct 90 ms 108224 KB Output is correct
74 Correct 84 ms 101240 KB Output is correct
75 Correct 86 ms 111864 KB Output is correct
76 Correct 123 ms 128224 KB Output is correct
77 Correct 101 ms 128120 KB Output is correct
78 Correct 123 ms 98936 KB Output is correct
79 Correct 83 ms 102392 KB Output is correct
80 Correct 103 ms 125560 KB Output is correct
81 Correct 80 ms 103544 KB Output is correct
82 Correct 85 ms 109432 KB Output is correct
83 Correct 109 ms 133280 KB Output is correct
84 Correct 88 ms 114168 KB Output is correct
85 Correct 96 ms 124280 KB Output is correct
86 Correct 96 ms 121708 KB Output is correct
87 Correct 100 ms 111860 KB Output is correct
88 Correct 115 ms 134648 KB Output is correct
89 Correct 117 ms 134648 KB Output is correct
90 Correct 80 ms 113016 KB Output is correct
91 Correct 113 ms 134648 KB Output is correct
92 Correct 122 ms 134648 KB Output is correct
93 Correct 113 ms 132088 KB Output is correct