답안 #420807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
420807 2021-06-08T14:00:53 Z juancarlovieri Cigle (COI21_cigle) C++17
100 / 100
444 ms 134340 KB
#include <bits/stdc++.h>
using namespace std;

int dp[5005][5005];
int pref[5005][5005];

int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i) cin >> arr[i];
  for (int i = 1; i < n; ++i) {
    int cur = 0, prev = 0, v = 0;
    int i2 = i;
    for (int j = i; j < n; ++j) {
      cur += arr[j];
      while (i2 && prev < cur - arr[j]) {
        --i2;
        prev += arr[i2];
      }
      if (i2 && prev == cur - arr[j]) {
        if (prev) ++v;
        --i2;
        prev += arr[i2];
      }
      dp[i][j] = pref[i - 1][i2] + v;
      if (i != j) dp[i][j] = max(dp[i][j], dp[i][j - 1]);
      pref[j][i] = max(pref[j][i], dp[i][j]);
    }
    int r = i;
    for (int j = 0; j <= r; ++j) {
      pref[r][j] = dp[j][r];
      if (j) pref[r][j] = max(pref[r][j], pref[r][j - 1]);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) ans = max(ans, dp[i][n - 1]);
  cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 1 ms 972 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 972 KB Output is correct
20 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5196 KB Output is correct
2 Correct 5 ms 5196 KB Output is correct
3 Correct 5 ms 5196 KB Output is correct
4 Correct 5 ms 5176 KB Output is correct
5 Correct 6 ms 5196 KB Output is correct
6 Correct 6 ms 5196 KB Output is correct
7 Correct 5 ms 5196 KB Output is correct
8 Correct 5 ms 5196 KB Output is correct
9 Correct 5 ms 5196 KB Output is correct
10 Correct 5 ms 5196 KB Output is correct
11 Correct 6 ms 5228 KB Output is correct
12 Correct 5 ms 5196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 1 ms 972 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 972 KB Output is correct
20 Correct 1 ms 972 KB Output is correct
21 Correct 5 ms 5196 KB Output is correct
22 Correct 5 ms 5196 KB Output is correct
23 Correct 5 ms 5196 KB Output is correct
24 Correct 5 ms 5176 KB Output is correct
25 Correct 6 ms 5196 KB Output is correct
26 Correct 6 ms 5196 KB Output is correct
27 Correct 5 ms 5196 KB Output is correct
28 Correct 5 ms 5196 KB Output is correct
29 Correct 5 ms 5196 KB Output is correct
30 Correct 5 ms 5196 KB Output is correct
31 Correct 6 ms 5228 KB Output is correct
32 Correct 5 ms 5196 KB Output is correct
33 Correct 5 ms 5240 KB Output is correct
34 Correct 5 ms 5196 KB Output is correct
35 Correct 5 ms 5196 KB Output is correct
36 Correct 5 ms 5280 KB Output is correct
37 Correct 5 ms 5196 KB Output is correct
38 Correct 5 ms 5324 KB Output is correct
39 Correct 5 ms 5196 KB Output is correct
40 Correct 5 ms 5196 KB Output is correct
41 Correct 6 ms 5196 KB Output is correct
42 Correct 6 ms 5196 KB Output is correct
43 Correct 5 ms 5188 KB Output is correct
44 Correct 7 ms 5196 KB Output is correct
45 Correct 5 ms 5196 KB Output is correct
46 Correct 5 ms 5196 KB Output is correct
47 Correct 6 ms 5196 KB Output is correct
48 Correct 5 ms 5196 KB Output is correct
49 Correct 5 ms 5196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 1 ms 972 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 972 KB Output is correct
20 Correct 1 ms 972 KB Output is correct
21 Correct 5 ms 5196 KB Output is correct
22 Correct 5 ms 5196 KB Output is correct
23 Correct 5 ms 5196 KB Output is correct
24 Correct 5 ms 5176 KB Output is correct
25 Correct 6 ms 5196 KB Output is correct
26 Correct 6 ms 5196 KB Output is correct
27 Correct 5 ms 5196 KB Output is correct
28 Correct 5 ms 5196 KB Output is correct
29 Correct 5 ms 5196 KB Output is correct
30 Correct 5 ms 5196 KB Output is correct
31 Correct 6 ms 5228 KB Output is correct
32 Correct 5 ms 5196 KB Output is correct
33 Correct 5 ms 5240 KB Output is correct
34 Correct 5 ms 5196 KB Output is correct
35 Correct 5 ms 5196 KB Output is correct
36 Correct 5 ms 5280 KB Output is correct
37 Correct 5 ms 5196 KB Output is correct
38 Correct 5 ms 5324 KB Output is correct
39 Correct 5 ms 5196 KB Output is correct
40 Correct 5 ms 5196 KB Output is correct
41 Correct 6 ms 5196 KB Output is correct
42 Correct 6 ms 5196 KB Output is correct
43 Correct 5 ms 5188 KB Output is correct
44 Correct 7 ms 5196 KB Output is correct
45 Correct 5 ms 5196 KB Output is correct
46 Correct 5 ms 5196 KB Output is correct
47 Correct 6 ms 5196 KB Output is correct
48 Correct 5 ms 5196 KB Output is correct
49 Correct 5 ms 5196 KB Output is correct
50 Correct 392 ms 134216 KB Output is correct
51 Correct 390 ms 134156 KB Output is correct
52 Correct 397 ms 134216 KB Output is correct
53 Correct 402 ms 134192 KB Output is correct
54 Correct 410 ms 134232 KB Output is correct
55 Correct 412 ms 134296 KB Output is correct
56 Correct 416 ms 134160 KB Output is correct
57 Correct 419 ms 134340 KB Output is correct
58 Correct 429 ms 134148 KB Output is correct
59 Correct 406 ms 134208 KB Output is correct
60 Correct 405 ms 134156 KB Output is correct
61 Correct 444 ms 134232 KB Output is correct
62 Correct 371 ms 134136 KB Output is correct
63 Correct 421 ms 134200 KB Output is correct
64 Correct 404 ms 134204 KB Output is correct
65 Correct 436 ms 134160 KB Output is correct
66 Correct 405 ms 134340 KB Output is correct
67 Correct 416 ms 134212 KB Output is correct
68 Correct 412 ms 134236 KB Output is correct
69 Correct 402 ms 134176 KB Output is correct
70 Correct 433 ms 134192 KB Output is correct
71 Correct 435 ms 134232 KB Output is correct
72 Correct 428 ms 134196 KB Output is correct