답안 #1002882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1002882 2024-06-19T21:00:24 Z Lobo Cigle (COI21_cigle) C++17
0 / 100
2 ms 604 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
const int inf = 1e18+10;

int32_t main() {
	// #ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
	// #endif
	int n;
	cin >> n;
	vector<int> a(n+10);
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	vector<vector<int>> dp(n+10,vector<int>(n+10,-inf));
	
	for(int i = 1; i <= n; i++) dp[1][i] = 0;
	int ans = 0;

	for(int j = 1; j <= n; j++) {
		for(int i = 1; i <= j; i++) {
			set<int> sij;
			int sum = 0;
			for(int x = i; x < j; x++) {
				sum+= a[x];
				sij.insert(sum);
			}
			for(int k = 1; k <= i-1; k++) {
				int sm = 0;
				int qtd = 0;
				for(int x = i-1; x > k; x--) {
					sm+= a[x];
					if(sij.count(sm)) qtd++;
				}
				dp[i][j] = max(dp[i][j],dp[k][i-1]+qtd);
			}
		}
	}

	for(int i = 1; i <= n; i++) {
		ans = max(ans,dp[i][n]);
	}
	cout << ans << endl;
}

Compilation message

cigle.cpp: In function 'int32_t main()':
cigle.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen("in.in","r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~
cigle.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen("out.out","w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -