답안 #1002832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1002832 2024-06-19T20:23:02 Z PagodePaiva Cigle (COI21_cigle) C++17
33 / 100
275 ms 6748 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N =510;
const int inf = 1e9;

int n;
int dp[N][N][2];
int v[N];
int mark[N*N];

const int debug = 0;

int main(){
	cin >> n;
	for(int i = 1;i <= n;i++)
		cin >> v[i];
	for(int i = 1;i <= n;i++){
		dp[1][i][0] = 0;
		dp[1][i][1] = -inf;
	}		
	for(int i = 1;i < n;i++){
		for(int j = i;j < n;j++){
			//
			int t = 0;
			int l = i, r = j;
			vector <int> bons;
			t += v[i];
			for(int k = i+1;k <= j;k++){
				bons.push_back(t);
				mark[t] = 1;
				t += v[k];
			}
			int res = 0;
			dp[r+1][r+1][1] = max(dp[r+1][r+1][1], dp[l][r][0]);
			t -= v[r+1];
			for(int k = j+2;k <= n;k++){
				if(t >= 0 and mark[t] == 1){
					res++;
				}
				t -= v[k];
				dp[r+1][k][1] = max(dp[r+1][k][1], dp[l][r][0]+res);
			}
			for(auto x : bons){
				mark[x] = 0;
			}
			bons.clear();
			//
			t = 0;
			t += v[r];
			for(int k = r-1;k >= i;k--){
				bons.push_back(t);
				mark[t] = 1;
				t += v[k];
			}
			if(debug and l == 3 and r == 4){
				for(auto x : bons){
					cout << x << ' ';
				}
				cout << endl;
			}
			res = 0;
			t = v[r+1];
			if(debug and l == 3 and r == 4) cout << t << ' ';
			dp[r+1][r+1][0] = max(dp[r+1][r+1][0], dp[l][r][1] + res);
			for(int k = r+2;k <= n;k++){
				if(t < N*N and mark[t] == 1){
					res++;
				}
				t += v[k];
				if(debug and l == 3 and r == 4 and k == 6){
					cout << res << endl;
				}
				dp[r+1][k][0] = max(dp[r+1][k][0], dp[l][r][1]+res);
			}
			for(auto x : bons) mark[x] = 0;
				bons.clear();
		}
	}
	int res = 0;
	for(int i = 0;i <= n;i++){
		res = max(res, dp[i][n][0]);
		res = max(res, dp[i][n][1]);
	}
	cout << res << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 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 2 ms 604 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 2 ms 1472 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 2 ms 956 KB Output is correct
20 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 187 ms 2396 KB Output is correct
2 Correct 187 ms 2392 KB Output is correct
3 Correct 179 ms 2640 KB Output is correct
4 Correct 209 ms 2392 KB Output is correct
5 Correct 184 ms 2392 KB Output is correct
6 Correct 239 ms 2436 KB Output is correct
7 Correct 275 ms 2440 KB Output is correct
8 Correct 246 ms 2396 KB Output is correct
9 Correct 260 ms 2448 KB Output is correct
10 Correct 218 ms 2392 KB Output is correct
11 Correct 220 ms 2396 KB Output is correct
12 Correct 202 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 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 2 ms 604 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 2 ms 1472 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 2 ms 956 KB Output is correct
20 Correct 2 ms 860 KB Output is correct
21 Correct 187 ms 2396 KB Output is correct
22 Correct 187 ms 2392 KB Output is correct
23 Correct 179 ms 2640 KB Output is correct
24 Correct 209 ms 2392 KB Output is correct
25 Correct 184 ms 2392 KB Output is correct
26 Correct 239 ms 2436 KB Output is correct
27 Correct 275 ms 2440 KB Output is correct
28 Correct 246 ms 2396 KB Output is correct
29 Correct 260 ms 2448 KB Output is correct
30 Correct 218 ms 2392 KB Output is correct
31 Correct 220 ms 2396 KB Output is correct
32 Correct 202 ms 2392 KB Output is correct
33 Correct 200 ms 2436 KB Output is correct
34 Correct 189 ms 2396 KB Output is correct
35 Correct 176 ms 2436 KB Output is correct
36 Correct 173 ms 2436 KB Output is correct
37 Correct 242 ms 2440 KB Output is correct
38 Correct 244 ms 2392 KB Output is correct
39 Correct 227 ms 2396 KB Output is correct
40 Runtime error 5 ms 6748 KB Execution killed with signal 11
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 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 2 ms 604 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 2 ms 1472 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 2 ms 956 KB Output is correct
20 Correct 2 ms 860 KB Output is correct
21 Correct 187 ms 2396 KB Output is correct
22 Correct 187 ms 2392 KB Output is correct
23 Correct 179 ms 2640 KB Output is correct
24 Correct 209 ms 2392 KB Output is correct
25 Correct 184 ms 2392 KB Output is correct
26 Correct 239 ms 2436 KB Output is correct
27 Correct 275 ms 2440 KB Output is correct
28 Correct 246 ms 2396 KB Output is correct
29 Correct 260 ms 2448 KB Output is correct
30 Correct 218 ms 2392 KB Output is correct
31 Correct 220 ms 2396 KB Output is correct
32 Correct 202 ms 2392 KB Output is correct
33 Correct 200 ms 2436 KB Output is correct
34 Correct 189 ms 2396 KB Output is correct
35 Correct 176 ms 2436 KB Output is correct
36 Correct 173 ms 2436 KB Output is correct
37 Correct 242 ms 2440 KB Output is correct
38 Correct 244 ms 2392 KB Output is correct
39 Correct 227 ms 2396 KB Output is correct
40 Runtime error 5 ms 6748 KB Execution killed with signal 11
41 Halted 0 ms 0 KB -