Submission #244594

#TimeUsernameProblemLanguageResultExecution timeMemory
244594YeraBigger segments (IZhO19_segments)C++14
Compilation error
0 ms0 KiB
// In The Name Of God
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <bitset>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sagyndym_seni ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

const ll N = 5e5+5, p1 = 911382323, p2 = 972663749, INF = 1e18;

inline int read(){
	char c = getchar();
	bool minus = 0;
	while (c < '0' || '9' < c){
		if(c == '-'){ minus = 1;}
		c = getchar();
		if(c == '-'){ minus = 1;}
	}
	int res = 0;
	while ('0' <= c && c <= '9') {
		res = (res << 3) + (res << 1) + c - '0';
		c = getchar();
	}
	if(minus){ res *= -1;}
	return res;
}

ll a[N], p[N];
int n;
pair<ll, ll> dp[N];

ll get(int l, int r){
	if(r < l){ return 0;}
	return p[r] - (l == 0 ? 0 : p[l - 1]);
}

// {num of blocks, sum in last block}


int main(){
	n = read();
	for(int i = 1; i <= n; i++){
		a[i] = read();
		p[i] = a[i] + p[i - 1];
	}
	for(int r = 1; r <= n; r++){
		for(int l = r - 1; l >= 0; l--){
			ll sum = get(l, r);
			dp[r] = {0, INF};
			if(dp[l].s <= sum && dp[r].f < dp[l].f + 1){
				dp[r] = {dp[l].f + 1, min(sum, dp[r].s)};
			}
		}
	}
	cout<<dp[r].f;
	return 0;
}
/* TIMUS: 292220YC*/


Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:87:11: error: 'r' was not declared in this scope
  cout<<dp[r].f;
           ^