Submission #693891

# Submission time Handle Problem Language Result Execution time Memory
693891 2023-02-03T11:14:21 Z 79brue Cigle (COI21_cigle) C++17
100 / 100
258 ms 67360 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
int arr[5002], sum[5002];
int DP[5002][5002];
int maxV[5002];
int ans;

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d", &arr[i]), sum[i] = sum[i-1] + arr[i];
    for(int m=1; m<n; m++){
        /// Case 1. 아래가 더 짧거나 같다
        {
            int s = m, maxVal = 0, match = 0, nextturn = 0;
            for(int e=m+1; e<=n; e++){
                if(arr[m] > sum[e] - sum[m]) continue;
                if(nextturn) match++, nextturn = 0;
                while(s>1 && sum[e] - sum[m] >= sum[m] - sum[s-2]){
                    s--;
                    maxVal = max(maxVal, DP[s][m] + match);
                }
                if(sum[e] - sum[m] == sum[m] - sum[s-1]) nextturn = 1;
                DP[m+1][e] = max(DP[m+1][e], maxVal);
            }
        }
        /// Case 2. 위가 더 짧다
        {
            for(int i=1; i<=m; i++) maxV[i] = max(maxV[i-1], DP[i][m]);
            int s = m, match = 0, nextturn = 0;
            for(int e=m+1; e<=n; e++){
                if(nextturn) match++, nextturn = 0;
                while(s > 1 && sum[e] - sum[m] >= sum[m] - sum[s-1]){
                    if(sum[e] - sum[m] == sum[m] - sum[s-1]) nextturn = 1;
                    s--;
                }
                if(s == 1 && sum[e] - sum[m] >= sum[m] - sum[s-1]) break;
                DP[m+1][e] = max(DP[m+1][e], match + maxV[s]);
            }
        }
    }
//    for(int i=1; i<=n; i++) for(int j=i; j<=n; j++) printf("%d %d: %d\n", i, j, DP[i][j]);
    for(int i=1; i<=n; i++) ans = max(ans, DP[i][n]);
    printf("%d", ans);
}

Compilation message

cigle.cpp: In function 'int main()':
cigle.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
cigle.cpp:15:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     for(int i=1; i<=n; i++) scanf("%d", &arr[i]), sum[i] = sum[i-1] + arr[i];
      |                             ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 564 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2772 KB Output is correct
2 Correct 3 ms 2772 KB Output is correct
3 Correct 3 ms 2772 KB Output is correct
4 Correct 3 ms 2772 KB Output is correct
5 Correct 3 ms 2772 KB Output is correct
6 Correct 4 ms 2772 KB Output is correct
7 Correct 3 ms 2772 KB Output is correct
8 Correct 3 ms 2772 KB Output is correct
9 Correct 3 ms 2772 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 3 ms 2772 KB Output is correct
12 Correct 4 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 564 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 3 ms 2772 KB Output is correct
22 Correct 3 ms 2772 KB Output is correct
23 Correct 3 ms 2772 KB Output is correct
24 Correct 3 ms 2772 KB Output is correct
25 Correct 3 ms 2772 KB Output is correct
26 Correct 4 ms 2772 KB Output is correct
27 Correct 3 ms 2772 KB Output is correct
28 Correct 3 ms 2772 KB Output is correct
29 Correct 3 ms 2772 KB Output is correct
30 Correct 3 ms 2772 KB Output is correct
31 Correct 3 ms 2772 KB Output is correct
32 Correct 4 ms 2772 KB Output is correct
33 Correct 3 ms 2772 KB Output is correct
34 Correct 3 ms 2772 KB Output is correct
35 Correct 3 ms 2772 KB Output is correct
36 Correct 3 ms 2736 KB Output is correct
37 Correct 3 ms 2772 KB Output is correct
38 Correct 3 ms 2736 KB Output is correct
39 Correct 3 ms 2772 KB Output is correct
40 Correct 3 ms 2772 KB Output is correct
41 Correct 3 ms 2772 KB Output is correct
42 Correct 3 ms 2736 KB Output is correct
43 Correct 3 ms 2772 KB Output is correct
44 Correct 4 ms 2772 KB Output is correct
45 Correct 3 ms 2708 KB Output is correct
46 Correct 3 ms 2772 KB Output is correct
47 Correct 4 ms 2772 KB Output is correct
48 Correct 3 ms 2744 KB Output is correct
49 Correct 3 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 564 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 3 ms 2772 KB Output is correct
22 Correct 3 ms 2772 KB Output is correct
23 Correct 3 ms 2772 KB Output is correct
24 Correct 3 ms 2772 KB Output is correct
25 Correct 3 ms 2772 KB Output is correct
26 Correct 4 ms 2772 KB Output is correct
27 Correct 3 ms 2772 KB Output is correct
28 Correct 3 ms 2772 KB Output is correct
29 Correct 3 ms 2772 KB Output is correct
30 Correct 3 ms 2772 KB Output is correct
31 Correct 3 ms 2772 KB Output is correct
32 Correct 4 ms 2772 KB Output is correct
33 Correct 3 ms 2772 KB Output is correct
34 Correct 3 ms 2772 KB Output is correct
35 Correct 3 ms 2772 KB Output is correct
36 Correct 3 ms 2736 KB Output is correct
37 Correct 3 ms 2772 KB Output is correct
38 Correct 3 ms 2736 KB Output is correct
39 Correct 3 ms 2772 KB Output is correct
40 Correct 3 ms 2772 KB Output is correct
41 Correct 3 ms 2772 KB Output is correct
42 Correct 3 ms 2736 KB Output is correct
43 Correct 3 ms 2772 KB Output is correct
44 Correct 4 ms 2772 KB Output is correct
45 Correct 3 ms 2708 KB Output is correct
46 Correct 3 ms 2772 KB Output is correct
47 Correct 4 ms 2772 KB Output is correct
48 Correct 3 ms 2744 KB Output is correct
49 Correct 3 ms 2772 KB Output is correct
50 Correct 194 ms 67360 KB Output is correct
51 Correct 196 ms 67360 KB Output is correct
52 Correct 196 ms 67260 KB Output is correct
53 Correct 195 ms 67272 KB Output is correct
54 Correct 234 ms 67192 KB Output is correct
55 Correct 202 ms 67224 KB Output is correct
56 Correct 245 ms 67272 KB Output is correct
57 Correct 244 ms 67280 KB Output is correct
58 Correct 247 ms 67312 KB Output is correct
59 Correct 257 ms 67316 KB Output is correct
60 Correct 258 ms 67268 KB Output is correct
61 Correct 229 ms 67244 KB Output is correct
62 Correct 231 ms 67272 KB Output is correct
63 Correct 215 ms 67228 KB Output is correct
64 Correct 220 ms 67216 KB Output is correct
65 Correct 214 ms 67316 KB Output is correct
66 Correct 225 ms 67264 KB Output is correct
67 Correct 204 ms 67204 KB Output is correct
68 Correct 206 ms 67284 KB Output is correct
69 Correct 205 ms 67220 KB Output is correct
70 Correct 245 ms 67232 KB Output is correct
71 Correct 258 ms 67240 KB Output is correct
72 Correct 231 ms 67240 KB Output is correct