답안 #706895

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
706895 2023-03-08T05:14:33 Z ld_minh4354 Bigger segments (IZhO19_segments) C++17
100 / 100
90 ms 22312 KB
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define debug(x) cout<<#x<<": "<<x<<"\n"

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//	freopen("input.000","r",stdin);
//	freopen("output.000","w",stdout);
//	srand((unsigned)time(NULL));
//	rand()
	
	int n,i,a[500005],opt;
	long long pre[500005];
	pair<int,long long> dp[500005];
	priority_queue<pair<long long,int>> q;
	
	cin>>n;
	
	for (i=1;i<n+1;i++) cin>>a[i];
	pre[1]=a[1];
	for (i=2;i<n+1;i++) pre[i]=pre[i-1]+a[i];
	
	q.push({-1e18,0});
	dp[1]={1,-a[1]};
	q.push({-a[1]-pre[1], 1});
	opt=0;
	for (i=2;i<n+1;i++)
	{
		dp[i]={1,-pre[i]};
		
		while (abs(q.top().fi)<=pre[i])
		{
			opt=max(q.top().se, opt);
			q.pop();
		}
		
		if (opt!=0) dp[i]=max(dp[i], {dp[opt].fi+1, -pre[i]+pre[opt]});
		
		q.push({dp[i].se-pre[i], i});
	}
	
//	for (i=1;i<n+1;i++) cout<<dp[i].fi<<" "<<dp[i].se<<"\n";
	cout<<dp[n].fi;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 13976 KB Output is correct
2 Correct 7 ms 13908 KB Output is correct
3 Correct 9 ms 13900 KB Output is correct
4 Correct 7 ms 13908 KB Output is correct
5 Correct 7 ms 13908 KB Output is correct
6 Correct 7 ms 14012 KB Output is correct
7 Correct 8 ms 13908 KB Output is correct
8 Correct 7 ms 13908 KB Output is correct
9 Correct 7 ms 13908 KB Output is correct
10 Correct 7 ms 13908 KB Output is correct
11 Correct 6 ms 14004 KB Output is correct
12 Correct 6 ms 13908 KB Output is correct
13 Correct 6 ms 13908 KB Output is correct
14 Correct 8 ms 13908 KB Output is correct
15 Correct 7 ms 13908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 13976 KB Output is correct
2 Correct 7 ms 13908 KB Output is correct
3 Correct 9 ms 13900 KB Output is correct
4 Correct 7 ms 13908 KB Output is correct
5 Correct 7 ms 13908 KB Output is correct
6 Correct 7 ms 14012 KB Output is correct
7 Correct 8 ms 13908 KB Output is correct
8 Correct 7 ms 13908 KB Output is correct
9 Correct 7 ms 13908 KB Output is correct
10 Correct 7 ms 13908 KB Output is correct
11 Correct 6 ms 14004 KB Output is correct
12 Correct 6 ms 13908 KB Output is correct
13 Correct 6 ms 13908 KB Output is correct
14 Correct 8 ms 13908 KB Output is correct
15 Correct 7 ms 13908 KB Output is correct
16 Correct 7 ms 14016 KB Output is correct
17 Correct 7 ms 13908 KB Output is correct
18 Correct 7 ms 13884 KB Output is correct
19 Correct 7 ms 13908 KB Output is correct
20 Correct 6 ms 13908 KB Output is correct
21 Correct 7 ms 14012 KB Output is correct
22 Correct 7 ms 13908 KB Output is correct
23 Correct 7 ms 13908 KB Output is correct
24 Correct 7 ms 13908 KB Output is correct
25 Correct 7 ms 13936 KB Output is correct
26 Correct 7 ms 13908 KB Output is correct
27 Correct 7 ms 13908 KB Output is correct
28 Correct 7 ms 13908 KB Output is correct
29 Correct 7 ms 13908 KB Output is correct
30 Correct 7 ms 13908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 13976 KB Output is correct
2 Correct 7 ms 13908 KB Output is correct
3 Correct 9 ms 13900 KB Output is correct
4 Correct 7 ms 13908 KB Output is correct
5 Correct 7 ms 13908 KB Output is correct
6 Correct 7 ms 14012 KB Output is correct
7 Correct 8 ms 13908 KB Output is correct
8 Correct 7 ms 13908 KB Output is correct
9 Correct 7 ms 13908 KB Output is correct
10 Correct 7 ms 13908 KB Output is correct
11 Correct 6 ms 14004 KB Output is correct
12 Correct 6 ms 13908 KB Output is correct
13 Correct 6 ms 13908 KB Output is correct
14 Correct 8 ms 13908 KB Output is correct
15 Correct 7 ms 13908 KB Output is correct
16 Correct 7 ms 14016 KB Output is correct
17 Correct 7 ms 13908 KB Output is correct
18 Correct 7 ms 13884 KB Output is correct
19 Correct 7 ms 13908 KB Output is correct
20 Correct 6 ms 13908 KB Output is correct
21 Correct 7 ms 14012 KB Output is correct
22 Correct 7 ms 13908 KB Output is correct
23 Correct 7 ms 13908 KB Output is correct
24 Correct 7 ms 13908 KB Output is correct
25 Correct 7 ms 13936 KB Output is correct
26 Correct 7 ms 13908 KB Output is correct
27 Correct 7 ms 13908 KB Output is correct
28 Correct 7 ms 13908 KB Output is correct
29 Correct 7 ms 13908 KB Output is correct
30 Correct 7 ms 13908 KB Output is correct
31 Correct 7 ms 14064 KB Output is correct
32 Correct 7 ms 14036 KB Output is correct
33 Correct 8 ms 13908 KB Output is correct
34 Correct 7 ms 14056 KB Output is correct
35 Correct 7 ms 13908 KB Output is correct
36 Correct 8 ms 13908 KB Output is correct
37 Correct 7 ms 14036 KB Output is correct
38 Correct 7 ms 13908 KB Output is correct
39 Correct 7 ms 13992 KB Output is correct
40 Correct 7 ms 13908 KB Output is correct
41 Correct 7 ms 13908 KB Output is correct
42 Correct 7 ms 14036 KB Output is correct
43 Correct 8 ms 14004 KB Output is correct
44 Correct 8 ms 13908 KB Output is correct
45 Correct 7 ms 13908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 13976 KB Output is correct
2 Correct 7 ms 13908 KB Output is correct
3 Correct 9 ms 13900 KB Output is correct
4 Correct 7 ms 13908 KB Output is correct
5 Correct 7 ms 13908 KB Output is correct
6 Correct 7 ms 14012 KB Output is correct
7 Correct 8 ms 13908 KB Output is correct
8 Correct 7 ms 13908 KB Output is correct
9 Correct 7 ms 13908 KB Output is correct
10 Correct 7 ms 13908 KB Output is correct
11 Correct 6 ms 14004 KB Output is correct
12 Correct 6 ms 13908 KB Output is correct
13 Correct 6 ms 13908 KB Output is correct
14 Correct 8 ms 13908 KB Output is correct
15 Correct 7 ms 13908 KB Output is correct
16 Correct 7 ms 14016 KB Output is correct
17 Correct 7 ms 13908 KB Output is correct
18 Correct 7 ms 13884 KB Output is correct
19 Correct 7 ms 13908 KB Output is correct
20 Correct 6 ms 13908 KB Output is correct
21 Correct 7 ms 14012 KB Output is correct
22 Correct 7 ms 13908 KB Output is correct
23 Correct 7 ms 13908 KB Output is correct
24 Correct 7 ms 13908 KB Output is correct
25 Correct 7 ms 13936 KB Output is correct
26 Correct 7 ms 13908 KB Output is correct
27 Correct 7 ms 13908 KB Output is correct
28 Correct 7 ms 13908 KB Output is correct
29 Correct 7 ms 13908 KB Output is correct
30 Correct 7 ms 13908 KB Output is correct
31 Correct 7 ms 14064 KB Output is correct
32 Correct 7 ms 14036 KB Output is correct
33 Correct 8 ms 13908 KB Output is correct
34 Correct 7 ms 14056 KB Output is correct
35 Correct 7 ms 13908 KB Output is correct
36 Correct 8 ms 13908 KB Output is correct
37 Correct 7 ms 14036 KB Output is correct
38 Correct 7 ms 13908 KB Output is correct
39 Correct 7 ms 13992 KB Output is correct
40 Correct 7 ms 13908 KB Output is correct
41 Correct 7 ms 13908 KB Output is correct
42 Correct 7 ms 14036 KB Output is correct
43 Correct 8 ms 14004 KB Output is correct
44 Correct 8 ms 13908 KB Output is correct
45 Correct 7 ms 13908 KB Output is correct
46 Correct 15 ms 16208 KB Output is correct
47 Correct 25 ms 14372 KB Output is correct
48 Correct 21 ms 14036 KB Output is correct
49 Correct 18 ms 14388 KB Output is correct
50 Correct 19 ms 14016 KB Output is correct
51 Correct 23 ms 14024 KB Output is correct
52 Correct 14 ms 13908 KB Output is correct
53 Correct 11 ms 13908 KB Output is correct
54 Correct 18 ms 13908 KB Output is correct
55 Correct 22 ms 13908 KB Output is correct
56 Correct 16 ms 13908 KB Output is correct
57 Correct 18 ms 15160 KB Output is correct
58 Correct 17 ms 14620 KB Output is correct
59 Correct 18 ms 14008 KB Output is correct
60 Correct 16 ms 13908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 13976 KB Output is correct
2 Correct 7 ms 13908 KB Output is correct
3 Correct 9 ms 13900 KB Output is correct
4 Correct 7 ms 13908 KB Output is correct
5 Correct 7 ms 13908 KB Output is correct
6 Correct 7 ms 14012 KB Output is correct
7 Correct 8 ms 13908 KB Output is correct
8 Correct 7 ms 13908 KB Output is correct
9 Correct 7 ms 13908 KB Output is correct
10 Correct 7 ms 13908 KB Output is correct
11 Correct 6 ms 14004 KB Output is correct
12 Correct 6 ms 13908 KB Output is correct
13 Correct 6 ms 13908 KB Output is correct
14 Correct 8 ms 13908 KB Output is correct
15 Correct 7 ms 13908 KB Output is correct
16 Correct 7 ms 14016 KB Output is correct
17 Correct 7 ms 13908 KB Output is correct
18 Correct 7 ms 13884 KB Output is correct
19 Correct 7 ms 13908 KB Output is correct
20 Correct 6 ms 13908 KB Output is correct
21 Correct 7 ms 14012 KB Output is correct
22 Correct 7 ms 13908 KB Output is correct
23 Correct 7 ms 13908 KB Output is correct
24 Correct 7 ms 13908 KB Output is correct
25 Correct 7 ms 13936 KB Output is correct
26 Correct 7 ms 13908 KB Output is correct
27 Correct 7 ms 13908 KB Output is correct
28 Correct 7 ms 13908 KB Output is correct
29 Correct 7 ms 13908 KB Output is correct
30 Correct 7 ms 13908 KB Output is correct
31 Correct 7 ms 14064 KB Output is correct
32 Correct 7 ms 14036 KB Output is correct
33 Correct 8 ms 13908 KB Output is correct
34 Correct 7 ms 14056 KB Output is correct
35 Correct 7 ms 13908 KB Output is correct
36 Correct 8 ms 13908 KB Output is correct
37 Correct 7 ms 14036 KB Output is correct
38 Correct 7 ms 13908 KB Output is correct
39 Correct 7 ms 13992 KB Output is correct
40 Correct 7 ms 13908 KB Output is correct
41 Correct 7 ms 13908 KB Output is correct
42 Correct 7 ms 14036 KB Output is correct
43 Correct 8 ms 14004 KB Output is correct
44 Correct 8 ms 13908 KB Output is correct
45 Correct 7 ms 13908 KB Output is correct
46 Correct 15 ms 16208 KB Output is correct
47 Correct 25 ms 14372 KB Output is correct
48 Correct 21 ms 14036 KB Output is correct
49 Correct 18 ms 14388 KB Output is correct
50 Correct 19 ms 14016 KB Output is correct
51 Correct 23 ms 14024 KB Output is correct
52 Correct 14 ms 13908 KB Output is correct
53 Correct 11 ms 13908 KB Output is correct
54 Correct 18 ms 13908 KB Output is correct
55 Correct 22 ms 13908 KB Output is correct
56 Correct 16 ms 13908 KB Output is correct
57 Correct 18 ms 15160 KB Output is correct
58 Correct 17 ms 14620 KB Output is correct
59 Correct 18 ms 14008 KB Output is correct
60 Correct 16 ms 13908 KB Output is correct
61 Correct 46 ms 22312 KB Output is correct
62 Correct 77 ms 20164 KB Output is correct
63 Correct 85 ms 18428 KB Output is correct
64 Correct 71 ms 18464 KB Output is correct
65 Correct 65 ms 18840 KB Output is correct
66 Correct 90 ms 18844 KB Output is correct
67 Correct 83 ms 17868 KB Output is correct
68 Correct 50 ms 15940 KB Output is correct
69 Correct 70 ms 15016 KB Output is correct
70 Correct 84 ms 18856 KB Output is correct
71 Correct 45 ms 15908 KB Output is correct
72 Correct 67 ms 20620 KB Output is correct
73 Correct 60 ms 19100 KB Output is correct
74 Correct 68 ms 17188 KB Output is correct
75 Correct 56 ms 17232 KB Output is correct