답안 #176028

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
176028 2020-01-07T17:09:17 Z maskoff Bigger segments (IZhO19_segments) C++14
0 / 100
2 ms 376 KB
#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 int inf = 1e9;
const int MOD = 1e9 + 7;
                                                                 
int main() {
/*#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);  
#endif            */                                          
    ios_base::sync_with_stdio(false);
  	cin.tie(nullptr);
  	int n;
  	cin >> n;
  	vector<int> a(n + 1);
  	vector<ll>  pref(n + 1);
  	for (int i = 1; i <= n; i++)
  		cin >> a[i];
  	for (int i = 1; i <= n; i++)
  		pref[i] = pref[i - 1] + a[i];
  	vector<pair<int, ll>> d(n + 1);
  	map<ll, pair<ll, int>> ans;
  	vector<ll> all;
  	for (int i = 1; i <= n; i++) {
  		auto x = upper_bound(all.begin(), all.end(), pref[i]) - all.begin();
  		if (x == 0)	{
  			all.pb(pref[i] * 2);
  			ans[pref[i] * 2].fr = 1;
  			ans[pref[i] * 2].sc = pref[i];
  			continue;
  		}        
  		x--;
  		d[i].fr = ans[all[x]].fr + 1;
  		d[i].sc = pref[i] - ans[all[x]].sc;
  		if (ans[all.front()].fr < d[i].fr || (ans[all.front()].sc == d[i].fr && ans[all.front()].sc < d[i].sc)) {
  		 	all.pb(d[i].sc + pref[i]);
  		 	ans[d[i].sc + pref[i]].fr = d[i].fr;
  		 	ans[d[i].sc + pref[i]].sc = d[i].sc;
  		}
  	}
  	cout << d[n].fr;
    return false;
}               
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 252 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 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 252 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 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 252 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 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 252 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 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 252 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -