제출 #345618

#제출 시각아이디문제언어결과실행 시간메모리
345618maskoffBigger segments (IZhO19_segments)C++14
0 / 100
5 ms8172 KiB
#include <bits/stdc++.h>
 
#define file ""
 
#define all(x) x.begin(), x.end()
 
#define sc second
#define fr first
 
#define pb push_back
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
const ll inf = 1e18 + 5;
const ll mod = 1e9 + 7;
 
const int N = 5e5 + 5;
 
int dx[] = {+1, 0, -1, 0};
int dy[] = {0, +1, 0, -1};

ll p[N], a[N];
ll n;
vector<pair<ll, ll>> dp(N + 5);

int main() {  
	ios_base :: sync_with_stdio(false);               
	cin.tie(nullptr);                                               
	srand(time(nullptr));
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) p[i] += p[i - 1] + a[i];
	stack<pair<ll, ll>> s;
	for (int i = 1; i <= n; i++) {
		while (!s.empty() && dp[s.top().fr].sc + s.top().sc > p[i]) 
		 	s.pop();

		if (s.empty()) dp[i] = {1, p[i]};
		else dp[i] = {dp[s.top().fr].fr + 1, p[i] - p[s.top().fr]};
		s.push({i, p[i]});
	}
	cout << dp[n].fr;
  return 0;                   
}  
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...