Submission #364351

# Submission time Handle Problem Language Result Execution time Memory
364351 2021-02-09T02:36:09 Z Killer2501 Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
123 ms 130796 KB
#include <bits/stdc++.h>
#define pb push_back
#define task "sequence"
#define pll pair<ll, ll>
#define pii pair<vector<ll>, ll>
#define fi first
#define se second

using ll = long long;
const long long mod = 1e15+7;
const ll mod1 = 1e9+1;
const ll N = 205;
const int base = 350;
using ull = unsigned long long;
using namespace std;
string s, ss;
ll n, m, t, k, T, cnt, tong, a[N], c[N], b[N], dp[N][N][N][2];
vector<ll> adj[N], kq;
pll p[N];
int ans;
void Min(ll& x, ll y)
{
    if(x > y)x = y;
}
void sol()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        b[i] = m - a[i];
        //cout << b[i] <<" ";
    }
    for(int i = 1; i <= n; i ++)b[i] = m - a[n-i+1];
    //cout << '\n';
    c[0] = c[n+1] = -1;
    for(int i = 1; i <= n; i ++)cin >> c[i];
    for(int i = 0; i <= n; i ++)
        for(int j = 0; j <= n; j ++)
            for(int l = 0; l <= n; l ++)dp[i][j][l][0] = dp[i][j][l][1] = mod;
    dp[0][0][0][0] = dp[0][0][0][1] = 0;
    for(int i = 0; i <= n; i ++)
    {
        for(int j = 0; j <= n-i; j ++)
        {
            for(int l = 0; l <= n; l ++)
            {
                if(dp[i][j][l][0] != mod)
                {
                    ans = max(ans, l);
                    if(i < n)
                    {
                        k = dp[i][j][l][0] + a[i+1] - a[i];
                        Min(dp[i+1][j][l+(k<=c[i+1])][0], k);
                    }
                    if(j < n)
                    {
                        k = dp[i][j][l][0] + b[j+1] + a[i];
                        Min(dp[i][j+1][l+(k<=c[n-j])][1], k);
                    }
                }
                if(dp[i][j][l][1] != mod)
                {
                    ans = max(ans, l);
                    if(i < n)
                    {
                        k = dp[i][j][l][1] + b[j] + a[i+1];
                        Min(dp[i+1][j][l+(k<=c[i+1])][0], k);
                    }
                    if(j < n)
                    {
                        k = dp[i][j][l][1] + b[j+1] - b[j];
                        Min(dp[i][j+1][l+(k<=c[n-j])][1], k);
                    }

                }
               // cout << i <<" "<<j<<" "<<l<<" "<<dp[i][j][l][0]<<" "<<dp[i][j][l][1] << '\n';
            }
        }
    }
    cout << ans;
}

int main()
{
    if(fopen(task".in", "r")){
       freopen(task".in", "r", stdin);
       freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest;
    ntest =  1;
    //cin >> ntest;
    //cout << (1<<30) << '\n';
    while(ntest -- > 0)
    sol();

}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:87:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   87 |        freopen(task".in", "r", stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:88:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   88 |        freopen(task".out", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 748 KB Output is correct
20 Correct 1 ms 876 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 620 KB Output is correct
23 Correct 1 ms 1132 KB Output is correct
24 Correct 1 ms 1004 KB Output is correct
25 Correct 1 ms 1132 KB Output is correct
26 Correct 1 ms 1132 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 1 ms 1152 KB Output is correct
30 Correct 1 ms 1132 KB Output is correct
31 Correct 1 ms 1132 KB Output is correct
32 Correct 1 ms 1004 KB Output is correct
33 Correct 1 ms 1132 KB Output is correct
34 Correct 1 ms 1132 KB Output is correct
35 Correct 1 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
18 Correct 83 ms 104940 KB Output is correct
19 Correct 54 ms 63724 KB Output is correct
20 Correct 23 ms 34028 KB Output is correct
21 Correct 43 ms 60268 KB Output is correct
22 Correct 61 ms 77932 KB Output is correct
23 Correct 22 ms 29036 KB Output is correct
24 Correct 14 ms 22636 KB Output is correct
25 Correct 21 ms 28396 KB Output is correct
26 Correct 7 ms 10860 KB Output is correct
27 Correct 22 ms 29548 KB Output is correct
28 Correct 14 ms 21100 KB Output is correct
29 Correct 21 ms 30188 KB Output is correct
30 Correct 15 ms 23788 KB Output is correct
31 Correct 20 ms 28396 KB Output is correct
32 Correct 10 ms 14956 KB Output is correct
33 Correct 22 ms 28396 KB Output is correct
34 Correct 7 ms 10220 KB Output is correct
35 Correct 17 ms 27756 KB Output is correct
36 Correct 9 ms 13292 KB Output is correct
37 Correct 22 ms 29548 KB Output is correct
38 Correct 11 ms 16236 KB Output is correct
39 Correct 22 ms 30828 KB Output is correct
40 Correct 11 ms 18156 KB Output is correct
41 Correct 110 ms 129516 KB Output is correct
42 Correct 50 ms 87276 KB Output is correct
43 Correct 111 ms 129516 KB Output is correct
44 Correct 50 ms 86252 KB Output is correct
45 Correct 111 ms 129536 KB Output is correct
46 Correct 50 ms 87276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 748 KB Output is correct
20 Correct 1 ms 876 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 620 KB Output is correct
23 Correct 1 ms 1132 KB Output is correct
24 Correct 1 ms 1004 KB Output is correct
25 Correct 1 ms 1132 KB Output is correct
26 Correct 1 ms 1132 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 1 ms 1152 KB Output is correct
30 Correct 1 ms 1132 KB Output is correct
31 Correct 1 ms 1132 KB Output is correct
32 Correct 1 ms 1004 KB Output is correct
33 Correct 1 ms 1132 KB Output is correct
34 Correct 1 ms 1132 KB Output is correct
35 Correct 1 ms 1132 KB Output is correct
36 Correct 83 ms 104940 KB Output is correct
37 Correct 54 ms 63724 KB Output is correct
38 Correct 23 ms 34028 KB Output is correct
39 Correct 43 ms 60268 KB Output is correct
40 Correct 61 ms 77932 KB Output is correct
41 Correct 22 ms 29036 KB Output is correct
42 Correct 14 ms 22636 KB Output is correct
43 Correct 21 ms 28396 KB Output is correct
44 Correct 7 ms 10860 KB Output is correct
45 Correct 22 ms 29548 KB Output is correct
46 Correct 14 ms 21100 KB Output is correct
47 Correct 21 ms 30188 KB Output is correct
48 Correct 15 ms 23788 KB Output is correct
49 Correct 20 ms 28396 KB Output is correct
50 Correct 10 ms 14956 KB Output is correct
51 Correct 22 ms 28396 KB Output is correct
52 Correct 7 ms 10220 KB Output is correct
53 Correct 17 ms 27756 KB Output is correct
54 Correct 9 ms 13292 KB Output is correct
55 Correct 22 ms 29548 KB Output is correct
56 Correct 11 ms 16236 KB Output is correct
57 Correct 22 ms 30828 KB Output is correct
58 Correct 11 ms 18156 KB Output is correct
59 Correct 110 ms 129516 KB Output is correct
60 Correct 50 ms 87276 KB Output is correct
61 Correct 111 ms 129516 KB Output is correct
62 Correct 50 ms 86252 KB Output is correct
63 Correct 111 ms 129536 KB Output is correct
64 Correct 50 ms 87276 KB Output is correct
65 Correct 99 ms 117100 KB Output is correct
66 Correct 86 ms 107372 KB Output is correct
67 Correct 80 ms 102700 KB Output is correct
68 Correct 73 ms 94828 KB Output is correct
69 Correct 95 ms 115692 KB Output is correct
70 Correct 97 ms 110956 KB Output is correct
71 Correct 90 ms 112108 KB Output is correct
72 Correct 100 ms 113260 KB Output is correct
73 Correct 77 ms 105068 KB Output is correct
74 Correct 98 ms 98156 KB Output is correct
75 Correct 86 ms 108524 KB Output is correct
76 Correct 108 ms 124396 KB Output is correct
77 Correct 101 ms 124396 KB Output is correct
78 Correct 79 ms 95980 KB Output is correct
79 Correct 82 ms 99436 KB Output is correct
80 Correct 106 ms 121964 KB Output is correct
81 Correct 77 ms 100460 KB Output is correct
82 Correct 77 ms 106220 KB Output is correct
83 Correct 107 ms 129516 KB Output is correct
84 Correct 90 ms 111084 KB Output is correct
85 Correct 90 ms 120684 KB Output is correct
86 Correct 87 ms 118124 KB Output is correct
87 Correct 88 ms 108524 KB Output is correct
88 Correct 123 ms 130796 KB Output is correct
89 Correct 114 ms 130796 KB Output is correct
90 Correct 64 ms 109676 KB Output is correct
91 Correct 122 ms 130796 KB Output is correct
92 Correct 111 ms 130796 KB Output is correct
93 Correct 76 ms 128236 KB Output is correct