답안 #1008108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1008108 2024-06-26T07:41:06 Z phong Collecting Stamps 3 (JOI20_ho_t3) C++17
15 / 100
196 ms 270264 KB
#include<bits/stdc++.h>

#define ll 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:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main(){
      | ^~~~
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:70:9: warning: unused variable 'ans' [-Wunused-variable]
   70 |     int ans = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 270072 KB Output is correct
2 Correct 136 ms 270116 KB Output is correct
3 Correct 143 ms 270164 KB Output is correct
4 Correct 130 ms 270164 KB Output is correct
5 Correct 118 ms 270160 KB Output is correct
6 Correct 128 ms 270164 KB Output is correct
7 Correct 131 ms 270160 KB Output is correct
8 Correct 118 ms 270160 KB Output is correct
9 Correct 150 ms 270096 KB Output is correct
10 Correct 127 ms 269948 KB Output is correct
11 Correct 140 ms 270180 KB Output is correct
12 Correct 125 ms 270160 KB Output is correct
13 Correct 134 ms 270164 KB Output is correct
14 Correct 118 ms 270160 KB Output is correct
15 Correct 139 ms 270088 KB Output is correct
16 Correct 158 ms 269944 KB Output is correct
17 Correct 130 ms 270076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 270072 KB Output is correct
2 Correct 136 ms 270116 KB Output is correct
3 Correct 143 ms 270164 KB Output is correct
4 Correct 130 ms 270164 KB Output is correct
5 Correct 118 ms 270160 KB Output is correct
6 Correct 128 ms 270164 KB Output is correct
7 Correct 131 ms 270160 KB Output is correct
8 Correct 118 ms 270160 KB Output is correct
9 Correct 150 ms 270096 KB Output is correct
10 Correct 127 ms 269948 KB Output is correct
11 Correct 140 ms 270180 KB Output is correct
12 Correct 125 ms 270160 KB Output is correct
13 Correct 134 ms 270164 KB Output is correct
14 Correct 118 ms 270160 KB Output is correct
15 Correct 139 ms 270088 KB Output is correct
16 Correct 158 ms 269944 KB Output is correct
17 Correct 130 ms 270076 KB Output is correct
18 Incorrect 136 ms 270160 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 270072 KB Output is correct
2 Correct 136 ms 270116 KB Output is correct
3 Correct 143 ms 270164 KB Output is correct
4 Correct 130 ms 270164 KB Output is correct
5 Correct 118 ms 270160 KB Output is correct
6 Correct 128 ms 270164 KB Output is correct
7 Correct 131 ms 270160 KB Output is correct
8 Correct 118 ms 270160 KB Output is correct
9 Correct 150 ms 270096 KB Output is correct
10 Correct 127 ms 269948 KB Output is correct
11 Correct 140 ms 270180 KB Output is correct
12 Correct 125 ms 270160 KB Output is correct
13 Correct 134 ms 270164 KB Output is correct
14 Correct 118 ms 270160 KB Output is correct
15 Correct 139 ms 270088 KB Output is correct
16 Correct 158 ms 269944 KB Output is correct
17 Correct 130 ms 270076 KB Output is correct
18 Correct 187 ms 270136 KB Output is correct
19 Correct 160 ms 270040 KB Output is correct
20 Correct 140 ms 270080 KB Output is correct
21 Correct 143 ms 270160 KB Output is correct
22 Correct 175 ms 270160 KB Output is correct
23 Correct 130 ms 270012 KB Output is correct
24 Correct 128 ms 270192 KB Output is correct
25 Correct 142 ms 270068 KB Output is correct
26 Correct 129 ms 270164 KB Output is correct
27 Correct 123 ms 270160 KB Output is correct
28 Correct 149 ms 270008 KB Output is correct
29 Correct 149 ms 270160 KB Output is correct
30 Correct 131 ms 269964 KB Output is correct
31 Correct 127 ms 270164 KB Output is correct
32 Correct 134 ms 270264 KB Output is correct
33 Correct 145 ms 269980 KB Output is correct
34 Correct 141 ms 270012 KB Output is correct
35 Correct 136 ms 270072 KB Output is correct
36 Correct 133 ms 270160 KB Output is correct
37 Correct 143 ms 270164 KB Output is correct
38 Correct 136 ms 270164 KB Output is correct
39 Correct 145 ms 270164 KB Output is correct
40 Correct 123 ms 270160 KB Output is correct
41 Correct 196 ms 270160 KB Output is correct
42 Correct 179 ms 270164 KB Output is correct
43 Correct 161 ms 270160 KB Output is correct
44 Correct 176 ms 270164 KB Output is correct
45 Correct 162 ms 269940 KB Output is correct
46 Correct 168 ms 270160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 270072 KB Output is correct
2 Correct 136 ms 270116 KB Output is correct
3 Correct 143 ms 270164 KB Output is correct
4 Correct 130 ms 270164 KB Output is correct
5 Correct 118 ms 270160 KB Output is correct
6 Correct 128 ms 270164 KB Output is correct
7 Correct 131 ms 270160 KB Output is correct
8 Correct 118 ms 270160 KB Output is correct
9 Correct 150 ms 270096 KB Output is correct
10 Correct 127 ms 269948 KB Output is correct
11 Correct 140 ms 270180 KB Output is correct
12 Correct 125 ms 270160 KB Output is correct
13 Correct 134 ms 270164 KB Output is correct
14 Correct 118 ms 270160 KB Output is correct
15 Correct 139 ms 270088 KB Output is correct
16 Correct 158 ms 269944 KB Output is correct
17 Correct 130 ms 270076 KB Output is correct
18 Incorrect 136 ms 270160 KB Output isn't correct
19 Halted 0 ms 0 KB -