Submission #201032

# Submission time Handle Problem Language Result Execution time Memory
201032 2020-02-09T06:36:31 Z HellAngel Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
133 ms 69984 KB
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int maxn = 207;

int dp[maxn][maxn][maxn][2], x[maxn], t[maxn], n, l, sum, ans;

/// left, right, cnt, curpos

int Dist(int i, int j)
{
    return min(abs(i - j), min(i, l - i) + min(j, l - j));
}

void Minimize(int &a, int b, bool check)
{
    if(check)
    a = min(a, b);
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
    cin >> n >> l;
    fill_n(&dp[0][0][0][0], maxn * maxn * maxn * 2, inf);
    for(int i = 1; i <= n; i++) cin >> x[i];
    for(int i = 1; i <= n; i++) cin >> t[i];
    dp[0][0][0][0] = dp[0][0][0][1] = 0;
    for(int len = 1; len <= n; len++)
    {
        for(int r = 0; r <= len; r++)
        {
            int l = len - r;
            for(int cnt = 0; cnt <= len; cnt++)
            {
                if(cnt < len)
                {
                    if(l > 0)
                    {
                        Minimize(dp[l][r][cnt][0], dp[l - 1][r][cnt][0] + Dist(x[l], x[l - 1]), 1);
                        Minimize(dp[l][r][cnt][0], dp[l - 1][r][cnt][1] + Dist(x[n - r + 1], x[l]), 1);
                    }
                    if(r > 0)
                    {
                        Minimize(dp[l][r][cnt][1], dp[l][r - 1][cnt][0] + Dist(x[l], x[n - r + 1]), 1);
                        Minimize(dp[l][r][cnt][1], dp[l][r - 1][cnt][1] + Dist(x[n - r + 2], x[n - r + 1]), 1);
                    }
                }
                if(cnt > 0)
                {
                    if(l > 0)
                    {
                        int val;
                        val = dp[l - 1][r][cnt - 1][0] + Dist(x[l], x[l - 1]);
                        Minimize(dp[l][r][cnt][0], val, val <= t[l]);
                        val = dp[l - 1][r][cnt - 1][1] + Dist(x[n - r + 1], x[l]);
                        Minimize(dp[l][r][cnt][0], val, val <= t[l]);
                    }
                    if(r > 0)
                    {
                        int val;
                        val = dp[l][r - 1][cnt - 1][0] + Dist(x[l], x[n - r + 1]);
                        Minimize(dp[l][r][cnt][1], val, val <= t[n - r + 1]);
                        val = dp[l][r - 1][cnt - 1][1] + Dist(x[n - r + 2], x[n - r + 1]);
                        Minimize(dp[l][r][cnt][1], val, val <= t[n - r + 1]);
                    }
                }
                if(dp[l][r][cnt][0] != inf) 
                {
                    ans = max(ans, cnt);
                }
                if(dp[l][r][cnt][1] != inf) ans = max(ans, cnt);
            }
        }
    }
    cout << ans;
}

Compilation message

ho_t3.cpp: In function 'int32_t main()':
ho_t3.cpp:25:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 47 ms 69752 KB Output is correct
2 Correct 47 ms 69752 KB Output is correct
3 Correct 47 ms 69752 KB Output is correct
4 Correct 45 ms 69752 KB Output is correct
5 Correct 49 ms 69752 KB Output is correct
6 Correct 45 ms 69752 KB Output is correct
7 Correct 46 ms 69752 KB Output is correct
8 Correct 48 ms 69728 KB Output is correct
9 Correct 49 ms 69752 KB Output is correct
10 Correct 43 ms 69752 KB Output is correct
11 Correct 56 ms 69752 KB Output is correct
12 Correct 45 ms 69752 KB Output is correct
13 Correct 52 ms 69752 KB Output is correct
14 Correct 51 ms 69752 KB Output is correct
15 Correct 48 ms 69752 KB Output is correct
16 Correct 48 ms 69752 KB Output is correct
17 Correct 47 ms 69752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 69752 KB Output is correct
2 Correct 47 ms 69752 KB Output is correct
3 Correct 47 ms 69752 KB Output is correct
4 Correct 45 ms 69752 KB Output is correct
5 Correct 49 ms 69752 KB Output is correct
6 Correct 45 ms 69752 KB Output is correct
7 Correct 46 ms 69752 KB Output is correct
8 Correct 48 ms 69728 KB Output is correct
9 Correct 49 ms 69752 KB Output is correct
10 Correct 43 ms 69752 KB Output is correct
11 Correct 56 ms 69752 KB Output is correct
12 Correct 45 ms 69752 KB Output is correct
13 Correct 52 ms 69752 KB Output is correct
14 Correct 51 ms 69752 KB Output is correct
15 Correct 48 ms 69752 KB Output is correct
16 Correct 48 ms 69752 KB Output is correct
17 Correct 47 ms 69752 KB Output is correct
18 Correct 53 ms 69728 KB Output is correct
19 Correct 43 ms 69728 KB Output is correct
20 Correct 51 ms 69756 KB Output is correct
21 Correct 46 ms 69752 KB Output is correct
22 Correct 42 ms 69752 KB Output is correct
23 Correct 48 ms 69752 KB Output is correct
24 Correct 48 ms 69752 KB Output is correct
25 Correct 50 ms 69752 KB Output is correct
26 Correct 45 ms 69752 KB Output is correct
27 Correct 47 ms 69752 KB Output is correct
28 Correct 50 ms 69752 KB Output is correct
29 Correct 51 ms 69752 KB Output is correct
30 Correct 52 ms 69752 KB Output is correct
31 Correct 47 ms 69768 KB Output is correct
32 Correct 47 ms 69752 KB Output is correct
33 Correct 52 ms 69752 KB Output is correct
34 Correct 47 ms 69752 KB Output is correct
35 Correct 46 ms 69744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 69752 KB Output is correct
2 Correct 47 ms 69752 KB Output is correct
3 Correct 47 ms 69752 KB Output is correct
4 Correct 45 ms 69752 KB Output is correct
5 Correct 49 ms 69752 KB Output is correct
6 Correct 45 ms 69752 KB Output is correct
7 Correct 46 ms 69752 KB Output is correct
8 Correct 48 ms 69728 KB Output is correct
9 Correct 49 ms 69752 KB Output is correct
10 Correct 43 ms 69752 KB Output is correct
11 Correct 56 ms 69752 KB Output is correct
12 Correct 45 ms 69752 KB Output is correct
13 Correct 52 ms 69752 KB Output is correct
14 Correct 51 ms 69752 KB Output is correct
15 Correct 48 ms 69752 KB Output is correct
16 Correct 48 ms 69752 KB Output is correct
17 Correct 47 ms 69752 KB Output is correct
18 Correct 102 ms 69880 KB Output is correct
19 Correct 74 ms 69808 KB Output is correct
20 Correct 66 ms 69752 KB Output is correct
21 Correct 71 ms 69752 KB Output is correct
22 Correct 82 ms 69752 KB Output is correct
23 Correct 55 ms 69752 KB Output is correct
24 Correct 51 ms 69752 KB Output is correct
25 Correct 53 ms 69752 KB Output is correct
26 Correct 47 ms 69752 KB Output is correct
27 Correct 57 ms 69752 KB Output is correct
28 Correct 59 ms 69752 KB Output is correct
29 Correct 53 ms 69880 KB Output is correct
30 Correct 59 ms 69752 KB Output is correct
31 Correct 53 ms 69752 KB Output is correct
32 Correct 49 ms 69752 KB Output is correct
33 Correct 53 ms 69752 KB Output is correct
34 Correct 48 ms 69816 KB Output is correct
35 Correct 53 ms 69752 KB Output is correct
36 Correct 49 ms 69752 KB Output is correct
37 Correct 55 ms 69752 KB Output is correct
38 Correct 50 ms 69752 KB Output is correct
39 Correct 55 ms 69752 KB Output is correct
40 Correct 51 ms 69752 KB Output is correct
41 Correct 119 ms 69752 KB Output is correct
42 Correct 86 ms 69880 KB Output is correct
43 Correct 118 ms 69828 KB Output is correct
44 Correct 82 ms 69752 KB Output is correct
45 Correct 125 ms 69752 KB Output is correct
46 Correct 90 ms 69880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 69752 KB Output is correct
2 Correct 47 ms 69752 KB Output is correct
3 Correct 47 ms 69752 KB Output is correct
4 Correct 45 ms 69752 KB Output is correct
5 Correct 49 ms 69752 KB Output is correct
6 Correct 45 ms 69752 KB Output is correct
7 Correct 46 ms 69752 KB Output is correct
8 Correct 48 ms 69728 KB Output is correct
9 Correct 49 ms 69752 KB Output is correct
10 Correct 43 ms 69752 KB Output is correct
11 Correct 56 ms 69752 KB Output is correct
12 Correct 45 ms 69752 KB Output is correct
13 Correct 52 ms 69752 KB Output is correct
14 Correct 51 ms 69752 KB Output is correct
15 Correct 48 ms 69752 KB Output is correct
16 Correct 48 ms 69752 KB Output is correct
17 Correct 47 ms 69752 KB Output is correct
18 Correct 53 ms 69728 KB Output is correct
19 Correct 43 ms 69728 KB Output is correct
20 Correct 51 ms 69756 KB Output is correct
21 Correct 46 ms 69752 KB Output is correct
22 Correct 42 ms 69752 KB Output is correct
23 Correct 48 ms 69752 KB Output is correct
24 Correct 48 ms 69752 KB Output is correct
25 Correct 50 ms 69752 KB Output is correct
26 Correct 45 ms 69752 KB Output is correct
27 Correct 47 ms 69752 KB Output is correct
28 Correct 50 ms 69752 KB Output is correct
29 Correct 51 ms 69752 KB Output is correct
30 Correct 52 ms 69752 KB Output is correct
31 Correct 47 ms 69768 KB Output is correct
32 Correct 47 ms 69752 KB Output is correct
33 Correct 52 ms 69752 KB Output is correct
34 Correct 47 ms 69752 KB Output is correct
35 Correct 46 ms 69744 KB Output is correct
36 Correct 102 ms 69880 KB Output is correct
37 Correct 74 ms 69808 KB Output is correct
38 Correct 66 ms 69752 KB Output is correct
39 Correct 71 ms 69752 KB Output is correct
40 Correct 82 ms 69752 KB Output is correct
41 Correct 55 ms 69752 KB Output is correct
42 Correct 51 ms 69752 KB Output is correct
43 Correct 53 ms 69752 KB Output is correct
44 Correct 47 ms 69752 KB Output is correct
45 Correct 57 ms 69752 KB Output is correct
46 Correct 59 ms 69752 KB Output is correct
47 Correct 53 ms 69880 KB Output is correct
48 Correct 59 ms 69752 KB Output is correct
49 Correct 53 ms 69752 KB Output is correct
50 Correct 49 ms 69752 KB Output is correct
51 Correct 53 ms 69752 KB Output is correct
52 Correct 48 ms 69816 KB Output is correct
53 Correct 53 ms 69752 KB Output is correct
54 Correct 49 ms 69752 KB Output is correct
55 Correct 55 ms 69752 KB Output is correct
56 Correct 50 ms 69752 KB Output is correct
57 Correct 55 ms 69752 KB Output is correct
58 Correct 51 ms 69752 KB Output is correct
59 Correct 119 ms 69752 KB Output is correct
60 Correct 86 ms 69880 KB Output is correct
61 Correct 118 ms 69828 KB Output is correct
62 Correct 82 ms 69752 KB Output is correct
63 Correct 125 ms 69752 KB Output is correct
64 Correct 90 ms 69880 KB Output is correct
65 Correct 109 ms 69752 KB Output is correct
66 Correct 101 ms 69752 KB Output is correct
67 Correct 97 ms 69752 KB Output is correct
68 Correct 94 ms 69752 KB Output is correct
69 Correct 108 ms 69984 KB Output is correct
70 Correct 108 ms 69816 KB Output is correct
71 Correct 104 ms 69752 KB Output is correct
72 Correct 109 ms 69756 KB Output is correct
73 Correct 105 ms 69880 KB Output is correct
74 Correct 97 ms 69884 KB Output is correct
75 Correct 100 ms 69752 KB Output is correct
76 Correct 119 ms 69752 KB Output is correct
77 Correct 121 ms 69820 KB Output is correct
78 Correct 100 ms 69768 KB Output is correct
79 Correct 100 ms 69752 KB Output is correct
80 Correct 118 ms 69752 KB Output is correct
81 Correct 97 ms 69880 KB Output is correct
82 Correct 110 ms 69752 KB Output is correct
83 Correct 116 ms 69728 KB Output is correct
84 Correct 104 ms 69752 KB Output is correct
85 Correct 115 ms 69820 KB Output is correct
86 Correct 110 ms 69756 KB Output is correct
87 Correct 97 ms 69752 KB Output is correct
88 Correct 133 ms 69752 KB Output is correct
89 Correct 122 ms 69880 KB Output is correct
90 Correct 101 ms 69752 KB Output is correct
91 Correct 123 ms 69752 KB Output is correct
92 Correct 120 ms 69752 KB Output is correct
93 Correct 116 ms 69752 KB Output is correct