Submission #290733

# Submission time Handle Problem Language Result Execution time Memory
290733 2020-09-04T11:44:21 Z Autoratch Bigger segments (IZhO19_segments) C++14
0 / 100
2 ms 512 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 5e5 + 1;

long long n,s[N],dp[N],mn[N];
vector<pair<long long,int> > res;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> n;
	for(int i = 1;i <= n;i++) cin >> s[i],s[i]+=s[i-1];
	for(int i = 1;i <= n;i++)
	{
		for(int j = 0;j+1 < res.size();j++) assert(res[j].first<=res[j+1].first);
		auto it = upper_bound(res.begin(),res.end(),make_pair(s[i],INT_MAX));
		if(it==res.begin())
		{
			dp[i] = 1;
			mn[i] = s[i];
		}
		else
		{
			it--;
			int x = it->second;
			dp[i] = dp[x]+1;
			mn[i] = s[i]-s[x];
		}
		res.push_back({mn[i]+s[i],i});
	}
	cout << dp[n];
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:17:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |   for(int j = 0;j+1 < res.size();j++) assert(res[j].first<=res[j+1].first);
      |                 ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Runtime error 2 ms 512 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Runtime error 2 ms 512 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Runtime error 2 ms 512 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Runtime error 2 ms 512 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Runtime error 2 ms 512 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -