Submission #889042

# Submission time Handle Problem Language Result Execution time Memory
889042 2023-12-18T16:41:18 Z Hakiers Cigle (COI21_cigle) C++17
0 / 100
1000 ms 22876 KB
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 5e3 + 7;
constexpr int oo = 1e9;
int dp[MAXN][MAXN][2];
int d[MAXN];
bool sum[MAXN*MAXN];
int res = 0;
int n;

int compute(int j, int k, int i, bool right){
	vector<int> tmp[2];
	
	for(int z = j; z <= i; z++)
		tmp[(z > k)].push_back(d[z]);
	

	reverse(tmp[!right].begin(), tmp[!right].end());
	
	
	
	int actsum = 0, cnt = 0;
	
	for(int z = 0; z + 1 < tmp[0].size(); z++){
		actsum += tmp[0][z];
		sum[actsum] = 1;
	}
	
	actsum = 0;
	
	for(int z = 0; z + 1 < tmp[1].size(); z++){
		actsum += tmp[1][z];
		if(sum[actsum]) cnt++;
	}
	
	actsum = 0;
	for(int z = 0; z + 1 < tmp[0].size(); z++){
		actsum += tmp[0][z];
		sum[actsum] = 0;
	}
	if(cnt == 0) return -oo;
	return cnt;
}

void solve(){
	for(int i = 0; i <= n; i++)
		for(int j = 0; j <= n; j++)
			dp[i][j][0] = dp[i][j][1] = -oo;
	
	for(int i = 1; i <= n; i++)
		dp[1][i][0] = 0;
	
	for(int i = 2; i <= n; i++){
		for(int k = i-1; k >= 1; k--){
			for(int j = k; j >= 1; j--){
				dp[k+1][i][0] = max(dp[k+1][i][0], dp[j][k][1] + compute(j, k, i, 0));
				dp[k+1][i][1] = max(dp[k+1][i][1], dp[j][k][0] + compute(j, k, i, 1));
				res = max({res, dp[k+1][i][0], dp[k+1][i][1]});
			}
		}
	}
	
	/*
	for(int i = 1; i <= n; i++){
		for(int k = 1; k <= n; k++){
			for(int j = k-1; j <= n; j++){
				for(int z = j; z < i; z++){
					dp[z+1][i][k] = max(dp[z+1][i][k], dp[j][z][k-1] + compute(j, z, i, (k%2)));
					res = max(res, dp[z+1][i][k]);
				}
			}
		}
	}
	*/
	
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	
	for(int i = 1; i <= n; i++)
		cin >> d[i];
	
	solve();
	cout << res << "\n";
}

Compilation message

cigle.cpp: In function 'int compute(int, int, int, bool)':
cigle.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for(int z = 0; z + 1 < tmp[0].size(); z++){
      |                 ~~~~~~^~~~~~~~~~~~~~~
cigle.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for(int z = 0; z + 1 < tmp[1].size(); z++){
      |                 ~~~~~~^~~~~~~~~~~~~~~
cigle.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for(int z = 0; z + 1 < tmp[0].size(); z++){
      |                 ~~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1065 ms 22876 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -