답안 #707938

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
707938 2023-03-10T14:28:05 Z penguin133 Cigle (COI21_cigle) C++17
100 / 100
229 ms 117404 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, q, A[5005], memo[505][505], dp[5005][5005];
/*
int dp(int x, int y){
	if(y >= n)return 0;
	if(memo[x][y] != -1)return memo[x][y];
	int ans = 0, cur = 0, in = y - 1, cnt = 0, tmp = 0;
	for(int i = y; i <= n; i++){
		cnt += A[i];
		while(cur < cnt && in >= x)cur += A[in--];
		
		ans = max(ans, tmp + dp(y, i + 1));
		if(cur == cnt && in >= x)tmp++;
	}
	return memo[x][y] = ans;
}
*/
int S[5005];
void solve(){
	cin >> n;
	for(int i=1;i<=n;i++)cin >> A[i];
	//memset(memo, -1, sizeof(memo));
	/*
	int ans = 0;
	for(int i=2;i<=n;i++)ans = max(ans, dp(1, i));// cout << dp(1, i) << ' ';
	cout << ans;
	*/
	for(int i=n;i>=1;i--){
		int cur = 0, in = i - 1, cnt = 0, tmp = 0, mx = 0; 
		S[n + 1] = 0;
		for(int j = n; j >= i; j --)S[j] = max(S[j+1], dp[i][j]);
		for(int j = i; j <= n; j++){
			cnt += A[j];
			while(cur < cnt && in >= 1){
				mx = max(mx, tmp + S[j+1]);
				dp[in][i] = mx;
				cur += A[in--];
			}
			if(cur == cnt && j != n)tmp++;
		}
		while(in >= 1)dp[in--][i] = max(mx, tmp);
	}
	cout << *max_element(dp[1], dp[1] + n + 1) << '\n';
	//for(int i=1;i<=n;i++){
	//	for(int j=1;j<=n;j++)cout << dp[i][j] << ' ';
		//cout << '\n';
	//}
	
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message

cigle.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 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 724 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 584 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 1 ms 596 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 588 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3284 KB Output is correct
2 Correct 3 ms 3284 KB Output is correct
3 Correct 2 ms 3272 KB Output is correct
4 Correct 3 ms 3284 KB Output is correct
5 Correct 2 ms 3284 KB Output is correct
6 Correct 3 ms 3284 KB Output is correct
7 Correct 3 ms 3284 KB Output is correct
8 Correct 3 ms 3284 KB Output is correct
9 Correct 3 ms 3280 KB Output is correct
10 Correct 3 ms 3284 KB Output is correct
11 Correct 3 ms 3276 KB Output is correct
12 Correct 3 ms 3284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 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 724 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 584 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 1 ms 596 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 588 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 2 ms 3284 KB Output is correct
22 Correct 3 ms 3284 KB Output is correct
23 Correct 2 ms 3272 KB Output is correct
24 Correct 3 ms 3284 KB Output is correct
25 Correct 2 ms 3284 KB Output is correct
26 Correct 3 ms 3284 KB Output is correct
27 Correct 3 ms 3284 KB Output is correct
28 Correct 3 ms 3284 KB Output is correct
29 Correct 3 ms 3280 KB Output is correct
30 Correct 3 ms 3284 KB Output is correct
31 Correct 3 ms 3276 KB Output is correct
32 Correct 3 ms 3284 KB Output is correct
33 Correct 2 ms 3272 KB Output is correct
34 Correct 2 ms 3284 KB Output is correct
35 Correct 2 ms 3284 KB Output is correct
36 Correct 2 ms 3284 KB Output is correct
37 Correct 4 ms 3352 KB Output is correct
38 Correct 2 ms 3336 KB Output is correct
39 Correct 3 ms 3284 KB Output is correct
40 Correct 5 ms 3280 KB Output is correct
41 Correct 3 ms 3284 KB Output is correct
42 Correct 2 ms 3276 KB Output is correct
43 Correct 3 ms 3284 KB Output is correct
44 Correct 3 ms 3284 KB Output is correct
45 Correct 3 ms 3252 KB Output is correct
46 Correct 3 ms 3272 KB Output is correct
47 Correct 3 ms 3272 KB Output is correct
48 Correct 2 ms 3284 KB Output is correct
49 Correct 2 ms 3284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 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 724 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 584 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 1 ms 596 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 588 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 2 ms 3284 KB Output is correct
22 Correct 3 ms 3284 KB Output is correct
23 Correct 2 ms 3272 KB Output is correct
24 Correct 3 ms 3284 KB Output is correct
25 Correct 2 ms 3284 KB Output is correct
26 Correct 3 ms 3284 KB Output is correct
27 Correct 3 ms 3284 KB Output is correct
28 Correct 3 ms 3284 KB Output is correct
29 Correct 3 ms 3280 KB Output is correct
30 Correct 3 ms 3284 KB Output is correct
31 Correct 3 ms 3276 KB Output is correct
32 Correct 3 ms 3284 KB Output is correct
33 Correct 2 ms 3272 KB Output is correct
34 Correct 2 ms 3284 KB Output is correct
35 Correct 2 ms 3284 KB Output is correct
36 Correct 2 ms 3284 KB Output is correct
37 Correct 4 ms 3352 KB Output is correct
38 Correct 2 ms 3336 KB Output is correct
39 Correct 3 ms 3284 KB Output is correct
40 Correct 5 ms 3280 KB Output is correct
41 Correct 3 ms 3284 KB Output is correct
42 Correct 2 ms 3276 KB Output is correct
43 Correct 3 ms 3284 KB Output is correct
44 Correct 3 ms 3284 KB Output is correct
45 Correct 3 ms 3252 KB Output is correct
46 Correct 3 ms 3272 KB Output is correct
47 Correct 3 ms 3272 KB Output is correct
48 Correct 2 ms 3284 KB Output is correct
49 Correct 2 ms 3284 KB Output is correct
50 Correct 210 ms 117324 KB Output is correct
51 Correct 197 ms 117400 KB Output is correct
52 Correct 208 ms 117324 KB Output is correct
53 Correct 208 ms 117396 KB Output is correct
54 Correct 223 ms 117372 KB Output is correct
55 Correct 225 ms 117356 KB Output is correct
56 Correct 211 ms 117372 KB Output is correct
57 Correct 210 ms 117292 KB Output is correct
58 Correct 229 ms 117384 KB Output is correct
59 Correct 216 ms 117328 KB Output is correct
60 Correct 222 ms 117336 KB Output is correct
61 Correct 210 ms 117356 KB Output is correct
62 Correct 203 ms 117316 KB Output is correct
63 Correct 221 ms 117292 KB Output is correct
64 Correct 212 ms 117372 KB Output is correct
65 Correct 207 ms 117296 KB Output is correct
66 Correct 212 ms 117404 KB Output is correct
67 Correct 194 ms 117316 KB Output is correct
68 Correct 198 ms 117340 KB Output is correct
69 Correct 208 ms 117320 KB Output is correct
70 Correct 227 ms 117384 KB Output is correct
71 Correct 229 ms 117376 KB Output is correct
72 Correct 215 ms 117316 KB Output is correct