답안 #1035557

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035557 2024-07-26T11:52:13 Z tvladm2009 Cigle (COI21_cigle) C++17
100 / 100
215 ms 117644 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define x first
#define y second
#define sz(a) a.size()

typedef long long ll;

const int N = 5e3 + 7;

int a[N];
ll dp[N][N], mx[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i - 1; j++) {
            mx[j] = dp[j][i - 1];
        }
        for (int j = 1; j <= i - 1; j++) {
            mx[j] = max(mx[j], mx[j - 1]);
        }
        ll sa = 0;
        ll sb = 0;
        ll x = 0;
        int cnt = 0;
        int pos = i - 1;
        for (int j = i; j <= n; j++) {
            sb += a[j];
            while (pos >= 1 && sa < sb) {
                sa += a[pos];
                pos--;
            }
            if (pos > 0 && sa == sb) {
                cnt++;
                x = max(x, mx[pos] + cnt);
            }
            dp[i][j + 1] = x;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) 
        ans = max(ans, dp[i][n]);
    cout << ans << "\n";
    return 0;
}
 

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 724 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3416 KB Output is correct
2 Correct 3 ms 3420 KB Output is correct
3 Correct 4 ms 3420 KB Output is correct
4 Correct 4 ms 3420 KB Output is correct
5 Correct 3 ms 3420 KB Output is correct
6 Correct 4 ms 3296 KB Output is correct
7 Correct 3 ms 3420 KB Output is correct
8 Correct 3 ms 3420 KB Output is correct
9 Correct 3 ms 3288 KB Output is correct
10 Correct 3 ms 3280 KB Output is correct
11 Correct 3 ms 3420 KB Output is correct
12 Correct 2 ms 3472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 724 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 3 ms 3416 KB Output is correct
22 Correct 3 ms 3420 KB Output is correct
23 Correct 4 ms 3420 KB Output is correct
24 Correct 4 ms 3420 KB Output is correct
25 Correct 3 ms 3420 KB Output is correct
26 Correct 4 ms 3296 KB Output is correct
27 Correct 3 ms 3420 KB Output is correct
28 Correct 3 ms 3420 KB Output is correct
29 Correct 3 ms 3288 KB Output is correct
30 Correct 3 ms 3280 KB Output is correct
31 Correct 3 ms 3420 KB Output is correct
32 Correct 2 ms 3472 KB Output is correct
33 Correct 4 ms 3416 KB Output is correct
34 Correct 3 ms 3416 KB Output is correct
35 Correct 3 ms 3672 KB Output is correct
36 Correct 2 ms 3420 KB Output is correct
37 Correct 3 ms 3420 KB Output is correct
38 Correct 3 ms 3420 KB Output is correct
39 Correct 4 ms 3420 KB Output is correct
40 Correct 2 ms 3420 KB Output is correct
41 Correct 3 ms 3280 KB Output is correct
42 Correct 3 ms 3420 KB Output is correct
43 Correct 2 ms 3420 KB Output is correct
44 Correct 2 ms 3420 KB Output is correct
45 Correct 2 ms 3312 KB Output is correct
46 Correct 3 ms 3288 KB Output is correct
47 Correct 4 ms 3420 KB Output is correct
48 Correct 2 ms 3420 KB Output is correct
49 Correct 2 ms 3540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 724 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 3 ms 3416 KB Output is correct
22 Correct 3 ms 3420 KB Output is correct
23 Correct 4 ms 3420 KB Output is correct
24 Correct 4 ms 3420 KB Output is correct
25 Correct 3 ms 3420 KB Output is correct
26 Correct 4 ms 3296 KB Output is correct
27 Correct 3 ms 3420 KB Output is correct
28 Correct 3 ms 3420 KB Output is correct
29 Correct 3 ms 3288 KB Output is correct
30 Correct 3 ms 3280 KB Output is correct
31 Correct 3 ms 3420 KB Output is correct
32 Correct 2 ms 3472 KB Output is correct
33 Correct 4 ms 3416 KB Output is correct
34 Correct 3 ms 3416 KB Output is correct
35 Correct 3 ms 3672 KB Output is correct
36 Correct 2 ms 3420 KB Output is correct
37 Correct 3 ms 3420 KB Output is correct
38 Correct 3 ms 3420 KB Output is correct
39 Correct 4 ms 3420 KB Output is correct
40 Correct 2 ms 3420 KB Output is correct
41 Correct 3 ms 3280 KB Output is correct
42 Correct 3 ms 3420 KB Output is correct
43 Correct 2 ms 3420 KB Output is correct
44 Correct 2 ms 3420 KB Output is correct
45 Correct 2 ms 3312 KB Output is correct
46 Correct 3 ms 3288 KB Output is correct
47 Correct 4 ms 3420 KB Output is correct
48 Correct 2 ms 3420 KB Output is correct
49 Correct 2 ms 3540 KB Output is correct
50 Correct 161 ms 117588 KB Output is correct
51 Correct 162 ms 117412 KB Output is correct
52 Correct 184 ms 117584 KB Output is correct
53 Correct 173 ms 117588 KB Output is correct
54 Correct 166 ms 117424 KB Output is correct
55 Correct 168 ms 117492 KB Output is correct
56 Correct 214 ms 117516 KB Output is correct
57 Correct 211 ms 117444 KB Output is correct
58 Correct 214 ms 117508 KB Output is correct
59 Correct 215 ms 117584 KB Output is correct
60 Correct 210 ms 117584 KB Output is correct
61 Correct 198 ms 117512 KB Output is correct
62 Correct 212 ms 117572 KB Output is correct
63 Correct 184 ms 117592 KB Output is correct
64 Correct 193 ms 117492 KB Output is correct
65 Correct 205 ms 117428 KB Output is correct
66 Correct 179 ms 117356 KB Output is correct
67 Correct 169 ms 117584 KB Output is correct
68 Correct 175 ms 117644 KB Output is correct
69 Correct 173 ms 117592 KB Output is correct
70 Correct 194 ms 117368 KB Output is correct
71 Correct 197 ms 117584 KB Output is correct
72 Correct 195 ms 117584 KB Output is correct