Submission #1129714

#TimeUsernameProblemLanguageResultExecution timeMemory
1129714zhasynBigger segments (IZhO19_segments)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 3000 + 100, M = 500 + 10, len = 315, inf = 1e18;
const ll mod = 998244353;
ll um(ll a, ll b){
	return (1LL * a * b) % mod;
}
ll subr(ll a, ll b){
	return ((1LL * a - b) % mod + mod) % mod;
}
ll bp(ll x, ll step){
	ll res = 1;
	while(step){
		if(step & 1) res = um(res, x);
		x = um(x, x);
		step /= 2;
	}
	return res;
}
ll inv(ll x){
	return bp(x, mod - 2);
}
ll a[N], dp[N][N];
int main() {
	//ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			dp[i][j] = -1;
		}
	}
	dp[0][0] = 0;
	for(int i = 0; i <= n; i++){
		ll sum = 0;
		for(int j = i + 1; j <= n; j++){
			sum += a[j];
			for(int k = 0; k < n; k++){
				if(dp[i][k] == -1 || sum < dp[i][k]) continue;
				if(dp[j][k + 1] == -1) dp[j][k + 1] = sum;
				else dp[j][k + 1] = min(dp[j][k + 1], sum);
			}
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(dp[n][i] != -1) ans = i;
	}
	
	ll sum = 0, prev = 0, cur = 0, mx = 0;
	for(int j = 0; j < n; j++){
		cur += a[j];
		if(cur >= prev){
			vec.pb(cur);
			prev = cur;
			cur = 0;
			mx++;
		}
	}
	if(abs(ans - mx) > 1) return -1;
	cout << ans;
  return 0;
}

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:67:25: error: 'vec' was not declared in this scope
   67 |                         vec.pb(cur);
      |                         ^~~