답안 #997926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
997926 2024-06-13T06:45:18 Z piOOE Cigle (COI21_cigle) C++17
100 / 100
180 ms 196692 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vector<int> d(n);
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
    }

    vector dp(n, vector<int>(n + 1)), pref(dp);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            pref[i][j + 1] = max(pref[i][j], dp[i][j]);
        }
//        if (i == 7) {
//            cout << "here!" << endl;
//        }
        int bal = 0, mx = 0, cnt = -1;
        for (int k = i + 1, j = i; k < n; ++k) {
            int add = 0;
            if (bal == 0) {
                add = 1;
                cnt += 1;
            }
            bal += d[k];
            while (j >= 0 && bal - d[j] >= 0) {
                mx = max(mx, cnt + dp[i][j] - add * (j == i));
                bal -= d[j--];
            }
            dp[k][i + 1] = mx;
            if (j >= 0) {
                dp[k][i + 1] = max(dp[k][i + 1], cnt + pref[i][j + 1]);
            }
        }
    }

//    cout << dp[7][2] << endl;

    cout << *max_element(dp[n - 1].begin(), dp[n - 1].end()) << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 456 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 2 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 2 ms 2452 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 456 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 2396 KB Output is correct
22 Correct 2 ms 2392 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2452 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 3 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 2 ms 2396 KB Output is correct
37 Correct 2 ms 2396 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 2 ms 2396 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
41 Correct 2 ms 2396 KB Output is correct
42 Correct 2 ms 2392 KB Output is correct
43 Correct 2 ms 2396 KB Output is correct
44 Correct 2 ms 2396 KB Output is correct
45 Correct 3 ms 2396 KB Output is correct
46 Correct 2 ms 2396 KB Output is correct
47 Correct 2 ms 2396 KB Output is correct
48 Correct 2 ms 2396 KB Output is correct
49 Correct 2 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 456 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 2396 KB Output is correct
22 Correct 2 ms 2392 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2452 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 3 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 2 ms 2396 KB Output is correct
37 Correct 2 ms 2396 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 2 ms 2396 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
41 Correct 2 ms 2396 KB Output is correct
42 Correct 2 ms 2392 KB Output is correct
43 Correct 2 ms 2396 KB Output is correct
44 Correct 2 ms 2396 KB Output is correct
45 Correct 3 ms 2396 KB Output is correct
46 Correct 2 ms 2396 KB Output is correct
47 Correct 2 ms 2396 KB Output is correct
48 Correct 2 ms 2396 KB Output is correct
49 Correct 2 ms 2392 KB Output is correct
50 Correct 154 ms 196300 KB Output is correct
51 Correct 161 ms 196364 KB Output is correct
52 Correct 155 ms 196340 KB Output is correct
53 Correct 155 ms 196432 KB Output is correct
54 Correct 155 ms 196436 KB Output is correct
55 Correct 161 ms 196524 KB Output is correct
56 Correct 163 ms 196384 KB Output is correct
57 Correct 165 ms 196384 KB Output is correct
58 Correct 179 ms 196692 KB Output is correct
59 Correct 178 ms 196440 KB Output is correct
60 Correct 176 ms 196432 KB Output is correct
61 Correct 162 ms 196408 KB Output is correct
62 Correct 162 ms 196468 KB Output is correct
63 Correct 157 ms 196436 KB Output is correct
64 Correct 156 ms 196436 KB Output is correct
65 Correct 159 ms 196432 KB Output is correct
66 Correct 169 ms 196432 KB Output is correct
67 Correct 156 ms 196536 KB Output is correct
68 Correct 155 ms 196432 KB Output is correct
69 Correct 156 ms 196532 KB Output is correct
70 Correct 180 ms 196432 KB Output is correct
71 Correct 176 ms 196388 KB Output is correct
72 Correct 170 ms 196364 KB Output is correct