Submission #1008133

# Submission time Handle Problem Language Result Execution time Memory
1008133 2024-06-26T07:53:48 Z phong Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
180 ms 270192 KB
#include<bits/stdc++.h>

#define ll long long
#define int long long
const int nmax = 200 + 5, N = 3e5 + 5;
const ll oo = 1e18;
const int lg = 7, M = 4e3;
const int base = 2e5, mod = 998244353;
#define pii pair<ll, ll>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' ';cout << endl
using namespace std;

int n, m, L;
int a[nmax * 2];
ll f[nmax][nmax * 2][nmax][2];
int b[nmax * 2];

void ckmin(ll &a, ll b){
    a = min(a, b);
}
int cost(int i, int j, int x, int cur){
    if(x > j){
        x -= m;
        return ((x >= i) == 0 && b[x] >= cur);
    }
    else{
        x += m;
        return ((x <= j) == 0 && b[x] >= cur);
    }
    return 0;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//        freopen("code.inp", "r", stdin);
//        freopen("code.out", "w", stdout);
    cin >> n >> L;
    memset(f, 0x3f, sizeof f);
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i = 1; i <= n; ++i) cin >> b[i];
    a[++n] = L;
    m = n - 1;
    for(int i = 1; i <= m; ++i){
        a[++n] = a[i];
        b[n] = b[i];
    }
    ++m;
    f[m][m][0][0] = f[m][m][0][1] = 0;
//    cout << cost(m, m, m - 1, 2) << ' ';
    for(int i = m; i >= 1; --i){
        for(int j = m; j <= n; ++j){
            for(int k = 0; k <= m; ++k){
                int res = a[m] - a[i];
                if(j != m) res += a[j];
                ckmin(f[i][j][k][0], f[i][j][k][1] + res);
                ckmin(f[i][j][k][1], f[i][j][k][0] + res);
                //
                ll cur = f[i][j][k][0] + abs(a[i - 1] - a[i]);
                ckmin(f[i - 1][j][k + cost(i, j, i - 1, cur)][0], cur);
                cur = f[i][j][k][1];
                if(j == m) cur += a[j + 1];
                else cur += a[j + 1] - a[j];
                ckmin(f[i][j + 1][k + cost(i, j, j + 1, cur)][1], cur);
            }
        }
    }
//    cout << f[5][m + 1][2][1] << ' ';
    int ans = 0;
    for(int k = m; k >= 0; --k){
        for(int i = 1; i <= m; ++i){
            for(int j = m; j <= n; ++j){
                if(min(f[i][j][k][0], f[i][j][k][1]) < oo) cout << k, exit(0);
            }
        }
    }

}
/*
4 5
3 1 3 7
3 2 0 4
1 2 5 1
4 2 4 9
3 4 3 9




*/

Compilation message

ho_t3.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   35 | main(){
      | ^~~~
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:71:9: warning: unused variable 'ans' [-Wunused-variable]
   71 |     int ans = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 97 ms 270160 KB Output is correct
2 Correct 110 ms 269984 KB Output is correct
3 Correct 104 ms 270160 KB Output is correct
4 Correct 108 ms 270164 KB Output is correct
5 Correct 93 ms 270108 KB Output is correct
6 Correct 104 ms 270176 KB Output is correct
7 Correct 114 ms 269936 KB Output is correct
8 Correct 91 ms 270012 KB Output is correct
9 Correct 104 ms 269984 KB Output is correct
10 Correct 95 ms 269948 KB Output is correct
11 Correct 99 ms 270028 KB Output is correct
12 Correct 95 ms 270164 KB Output is correct
13 Correct 98 ms 270164 KB Output is correct
14 Correct 93 ms 270164 KB Output is correct
15 Correct 106 ms 270164 KB Output is correct
16 Correct 92 ms 269976 KB Output is correct
17 Correct 101 ms 270056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 270160 KB Output is correct
2 Correct 110 ms 269984 KB Output is correct
3 Correct 104 ms 270160 KB Output is correct
4 Correct 108 ms 270164 KB Output is correct
5 Correct 93 ms 270108 KB Output is correct
6 Correct 104 ms 270176 KB Output is correct
7 Correct 114 ms 269936 KB Output is correct
8 Correct 91 ms 270012 KB Output is correct
9 Correct 104 ms 269984 KB Output is correct
10 Correct 95 ms 269948 KB Output is correct
11 Correct 99 ms 270028 KB Output is correct
12 Correct 95 ms 270164 KB Output is correct
13 Correct 98 ms 270164 KB Output is correct
14 Correct 93 ms 270164 KB Output is correct
15 Correct 106 ms 270164 KB Output is correct
16 Correct 92 ms 269976 KB Output is correct
17 Correct 101 ms 270056 KB Output is correct
18 Correct 97 ms 270096 KB Output is correct
19 Correct 94 ms 270044 KB Output is correct
20 Correct 102 ms 269964 KB Output is correct
21 Correct 93 ms 269976 KB Output is correct
22 Correct 99 ms 269952 KB Output is correct
23 Correct 105 ms 269980 KB Output is correct
24 Correct 90 ms 270164 KB Output is correct
25 Correct 110 ms 270124 KB Output is correct
26 Correct 106 ms 270024 KB Output is correct
27 Correct 108 ms 270004 KB Output is correct
28 Correct 91 ms 270160 KB Output is correct
29 Correct 92 ms 270160 KB Output is correct
30 Correct 96 ms 270164 KB Output is correct
31 Correct 90 ms 270060 KB Output is correct
32 Correct 89 ms 270164 KB Output is correct
33 Correct 88 ms 270008 KB Output is correct
34 Correct 89 ms 270040 KB Output is correct
35 Correct 94 ms 270164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 270160 KB Output is correct
2 Correct 110 ms 269984 KB Output is correct
3 Correct 104 ms 270160 KB Output is correct
4 Correct 108 ms 270164 KB Output is correct
5 Correct 93 ms 270108 KB Output is correct
6 Correct 104 ms 270176 KB Output is correct
7 Correct 114 ms 269936 KB Output is correct
8 Correct 91 ms 270012 KB Output is correct
9 Correct 104 ms 269984 KB Output is correct
10 Correct 95 ms 269948 KB Output is correct
11 Correct 99 ms 270028 KB Output is correct
12 Correct 95 ms 270164 KB Output is correct
13 Correct 98 ms 270164 KB Output is correct
14 Correct 93 ms 270164 KB Output is correct
15 Correct 106 ms 270164 KB Output is correct
16 Correct 92 ms 269976 KB Output is correct
17 Correct 101 ms 270056 KB Output is correct
18 Correct 140 ms 270112 KB Output is correct
19 Correct 108 ms 270052 KB Output is correct
20 Correct 101 ms 270160 KB Output is correct
21 Correct 111 ms 270164 KB Output is correct
22 Correct 111 ms 270160 KB Output is correct
23 Correct 98 ms 270088 KB Output is correct
24 Correct 86 ms 270160 KB Output is correct
25 Correct 93 ms 270160 KB Output is correct
26 Correct 95 ms 270160 KB Output is correct
27 Correct 107 ms 270164 KB Output is correct
28 Correct 93 ms 270160 KB Output is correct
29 Correct 99 ms 270160 KB Output is correct
30 Correct 91 ms 270160 KB Output is correct
31 Correct 95 ms 270160 KB Output is correct
32 Correct 89 ms 270120 KB Output is correct
33 Correct 98 ms 270164 KB Output is correct
34 Correct 92 ms 269944 KB Output is correct
35 Correct 96 ms 270156 KB Output is correct
36 Correct 88 ms 270164 KB Output is correct
37 Correct 111 ms 270160 KB Output is correct
38 Correct 96 ms 270160 KB Output is correct
39 Correct 114 ms 269996 KB Output is correct
40 Correct 94 ms 270168 KB Output is correct
41 Correct 131 ms 270160 KB Output is correct
42 Correct 127 ms 270056 KB Output is correct
43 Correct 126 ms 270160 KB Output is correct
44 Correct 125 ms 270164 KB Output is correct
45 Correct 133 ms 270164 KB Output is correct
46 Correct 154 ms 270160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 270160 KB Output is correct
2 Correct 110 ms 269984 KB Output is correct
3 Correct 104 ms 270160 KB Output is correct
4 Correct 108 ms 270164 KB Output is correct
5 Correct 93 ms 270108 KB Output is correct
6 Correct 104 ms 270176 KB Output is correct
7 Correct 114 ms 269936 KB Output is correct
8 Correct 91 ms 270012 KB Output is correct
9 Correct 104 ms 269984 KB Output is correct
10 Correct 95 ms 269948 KB Output is correct
11 Correct 99 ms 270028 KB Output is correct
12 Correct 95 ms 270164 KB Output is correct
13 Correct 98 ms 270164 KB Output is correct
14 Correct 93 ms 270164 KB Output is correct
15 Correct 106 ms 270164 KB Output is correct
16 Correct 92 ms 269976 KB Output is correct
17 Correct 101 ms 270056 KB Output is correct
18 Correct 97 ms 270096 KB Output is correct
19 Correct 94 ms 270044 KB Output is correct
20 Correct 102 ms 269964 KB Output is correct
21 Correct 93 ms 269976 KB Output is correct
22 Correct 99 ms 269952 KB Output is correct
23 Correct 105 ms 269980 KB Output is correct
24 Correct 90 ms 270164 KB Output is correct
25 Correct 110 ms 270124 KB Output is correct
26 Correct 106 ms 270024 KB Output is correct
27 Correct 108 ms 270004 KB Output is correct
28 Correct 91 ms 270160 KB Output is correct
29 Correct 92 ms 270160 KB Output is correct
30 Correct 96 ms 270164 KB Output is correct
31 Correct 90 ms 270060 KB Output is correct
32 Correct 89 ms 270164 KB Output is correct
33 Correct 88 ms 270008 KB Output is correct
34 Correct 89 ms 270040 KB Output is correct
35 Correct 94 ms 270164 KB Output is correct
36 Correct 140 ms 270112 KB Output is correct
37 Correct 108 ms 270052 KB Output is correct
38 Correct 101 ms 270160 KB Output is correct
39 Correct 111 ms 270164 KB Output is correct
40 Correct 111 ms 270160 KB Output is correct
41 Correct 98 ms 270088 KB Output is correct
42 Correct 86 ms 270160 KB Output is correct
43 Correct 93 ms 270160 KB Output is correct
44 Correct 95 ms 270160 KB Output is correct
45 Correct 107 ms 270164 KB Output is correct
46 Correct 93 ms 270160 KB Output is correct
47 Correct 99 ms 270160 KB Output is correct
48 Correct 91 ms 270160 KB Output is correct
49 Correct 95 ms 270160 KB Output is correct
50 Correct 89 ms 270120 KB Output is correct
51 Correct 98 ms 270164 KB Output is correct
52 Correct 92 ms 269944 KB Output is correct
53 Correct 96 ms 270156 KB Output is correct
54 Correct 88 ms 270164 KB Output is correct
55 Correct 111 ms 270160 KB Output is correct
56 Correct 96 ms 270160 KB Output is correct
57 Correct 114 ms 269996 KB Output is correct
58 Correct 94 ms 270168 KB Output is correct
59 Correct 131 ms 270160 KB Output is correct
60 Correct 127 ms 270056 KB Output is correct
61 Correct 126 ms 270160 KB Output is correct
62 Correct 125 ms 270164 KB Output is correct
63 Correct 133 ms 270164 KB Output is correct
64 Correct 154 ms 270160 KB Output is correct
65 Correct 129 ms 270160 KB Output is correct
66 Correct 131 ms 270080 KB Output is correct
67 Correct 139 ms 270080 KB Output is correct
68 Correct 129 ms 270028 KB Output is correct
69 Correct 126 ms 270108 KB Output is correct
70 Correct 135 ms 270160 KB Output is correct
71 Correct 180 ms 270164 KB Output is correct
72 Correct 113 ms 269976 KB Output is correct
73 Correct 128 ms 270164 KB Output is correct
74 Correct 114 ms 269976 KB Output is correct
75 Correct 128 ms 270164 KB Output is correct
76 Correct 128 ms 270164 KB Output is correct
77 Correct 130 ms 270160 KB Output is correct
78 Correct 112 ms 270160 KB Output is correct
79 Correct 126 ms 270160 KB Output is correct
80 Correct 119 ms 270160 KB Output is correct
81 Correct 130 ms 270164 KB Output is correct
82 Correct 138 ms 270164 KB Output is correct
83 Correct 147 ms 270048 KB Output is correct
84 Correct 133 ms 270188 KB Output is correct
85 Correct 127 ms 269944 KB Output is correct
86 Correct 140 ms 270160 KB Output is correct
87 Correct 136 ms 269956 KB Output is correct
88 Correct 139 ms 270164 KB Output is correct
89 Correct 140 ms 270192 KB Output is correct
90 Correct 149 ms 270160 KB Output is correct
91 Correct 127 ms 270008 KB Output is correct
92 Correct 134 ms 269996 KB Output is correct
93 Correct 178 ms 270136 KB Output is correct