답안 #173842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173842 2020-01-05T14:09:55 Z Trickster Bigger segments (IZhO19_segments) C++14
0 / 100
2 ms 376 KB
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define N 500010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <ll, ll>

using namespace std;

ll n;
ll ans;
ll v[N];
ll p[N];

int main()
{
	cin >> n;
	
	for(ll i = 1; i <= n; i++)
		cin >> v[i];
	
	for(ll i = n; i >= 1; i--) p[i] = p[i+1] + v[i];
	
	ll sum = 0;
	ll prev = 0;
	queue <ll> Q;
	for(ll i = 1; i <= n; i++) {
		sum += v[i];
		
		Q.push(i);
		
		if(!Q.empty() && sum >= prev) {
			while(!Q.empty() && ans) {
				if(sum-v[Q.front()] < prev) break;
				
				sum -= v[Q.front()];
				Q.pop();
			}
			
			Q.empty();
			prev = sum, sum = 0;
			
			if(i != n && p[i+1] < prev) break;
			
			ans ++;
		}
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -