# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
868995 | 2023-11-02T19:12:35 Z | alexdd | Bigger segments (IZhO19_segments) | C++17 | 169 ms | 26716 KB |
#include<bits/stdc++.h> using namespace std; #define int long long int n; int a[500005]; int dp[500005]; int ult[500005]; int pref[500005]; signed main() { cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; pref[i]=pref[i-1]+a[i]; } dp[0]=0; ult[0]=0; vector<int> dq; dq.push_back(0); for(int i=1;i<=n;i++) { /**dp[i]=-1; for(int x=i-1;x>=0;x--) { if(dp[x]+1<dp[i-1]) break; if(ult[x]+pref[x]<=pref[i]) { dp[i]=dp[x]+1; ult[i]=pref[i]-pref[x]; break; } }*/ int st,dr,mij; st=0; dr=(int)dq.size()-1; while(st<=dr) { mij=(st+dr)/2; if(ult[dq[mij]]+pref[dq[mij]]<=pref[i]) { if(mij==(int)dq.size()-1 || ult[dq[mij+1]]+pref[dq[mij+1]] > pref[i]) break; st=mij+1; } else dr=mij-1; } dp[i]=dp[dq[mij]]+1; ult[i]=pref[i]-pref[dq[mij]]; if(dp[i-1]>dp[i] || (dp[i-1]==dp[i] && ult[i-1]+a[i]<ult[i])) { dp[i]=dp[i-1]; ult[i]=ult[i-1]+a[i]; } while(ult[dq.back()]+pref[dq.back()] >= ult[i]+pref[i]) dq.pop_back(); dq.push_back(i); } cout<<dp[n]; return 0; } /** dp[i] = numarul maxime de secvente in care pot fi impartite primele i elemente ult[i] = suma ultimei secvente din solutia pt dp[i] dp[i] max= dp[i-1] dp[i] max= max(dp[x]+1) pt x = 0..i-1 && ult[x] + pref[x] <= pref[i] */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 1 ms | 6488 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6492 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 1 ms | 6492 KB | Output is correct |
13 | Correct | 1 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6492 KB | Output is correct |
15 | Correct | 1 ms | 6492 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 1 ms | 6488 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6492 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 1 ms | 6492 KB | Output is correct |
13 | Correct | 1 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6492 KB | Output is correct |
15 | Correct | 1 ms | 6492 KB | Output is correct |
16 | Correct | 1 ms | 6592 KB | Output is correct |
17 | Correct | 1 ms | 6492 KB | Output is correct |
18 | Correct | 1 ms | 6492 KB | Output is correct |
19 | Correct | 1 ms | 6492 KB | Output is correct |
20 | Correct | 1 ms | 6492 KB | Output is correct |
21 | Correct | 1 ms | 6492 KB | Output is correct |
22 | Correct | 1 ms | 6492 KB | Output is correct |
23 | Correct | 1 ms | 6492 KB | Output is correct |
24 | Correct | 1 ms | 6492 KB | Output is correct |
25 | Correct | 1 ms | 6492 KB | Output is correct |
26 | Correct | 1 ms | 6492 KB | Output is correct |
27 | Correct | 1 ms | 6492 KB | Output is correct |
28 | Correct | 1 ms | 6492 KB | Output is correct |
29 | Correct | 1 ms | 6492 KB | Output is correct |
30 | Correct | 1 ms | 6492 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 1 ms | 6488 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6492 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 1 ms | 6492 KB | Output is correct |
13 | Correct | 1 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6492 KB | Output is correct |
15 | Correct | 1 ms | 6492 KB | Output is correct |
16 | Correct | 1 ms | 6592 KB | Output is correct |
17 | Correct | 1 ms | 6492 KB | Output is correct |
18 | Correct | 1 ms | 6492 KB | Output is correct |
19 | Correct | 1 ms | 6492 KB | Output is correct |
20 | Correct | 1 ms | 6492 KB | Output is correct |
21 | Correct | 1 ms | 6492 KB | Output is correct |
22 | Correct | 1 ms | 6492 KB | Output is correct |
23 | Correct | 1 ms | 6492 KB | Output is correct |
24 | Correct | 1 ms | 6492 KB | Output is correct |
25 | Correct | 1 ms | 6492 KB | Output is correct |
26 | Correct | 1 ms | 6492 KB | Output is correct |
27 | Correct | 1 ms | 6492 KB | Output is correct |
28 | Correct | 1 ms | 6492 KB | Output is correct |
29 | Correct | 1 ms | 6492 KB | Output is correct |
30 | Correct | 1 ms | 6492 KB | Output is correct |
31 | Correct | 1 ms | 6492 KB | Output is correct |
32 | Correct | 2 ms | 6636 KB | Output is correct |
33 | Correct | 2 ms | 6492 KB | Output is correct |
34 | Correct | 2 ms | 6492 KB | Output is correct |
35 | Correct | 2 ms | 6492 KB | Output is correct |
36 | Correct | 2 ms | 6492 KB | Output is correct |
37 | Correct | 2 ms | 6492 KB | Output is correct |
38 | Correct | 1 ms | 6492 KB | Output is correct |
39 | Correct | 1 ms | 6488 KB | Output is correct |
40 | Correct | 2 ms | 6744 KB | Output is correct |
41 | Correct | 1 ms | 6492 KB | Output is correct |
42 | Correct | 1 ms | 6492 KB | Output is correct |
43 | Correct | 1 ms | 6492 KB | Output is correct |
44 | Correct | 2 ms | 6492 KB | Output is correct |
45 | Correct | 1 ms | 6492 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 1 ms | 6488 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6492 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 1 ms | 6492 KB | Output is correct |
13 | Correct | 1 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6492 KB | Output is correct |
15 | Correct | 1 ms | 6492 KB | Output is correct |
16 | Correct | 1 ms | 6592 KB | Output is correct |
17 | Correct | 1 ms | 6492 KB | Output is correct |
18 | Correct | 1 ms | 6492 KB | Output is correct |
19 | Correct | 1 ms | 6492 KB | Output is correct |
20 | Correct | 1 ms | 6492 KB | Output is correct |
21 | Correct | 1 ms | 6492 KB | Output is correct |
22 | Correct | 1 ms | 6492 KB | Output is correct |
23 | Correct | 1 ms | 6492 KB | Output is correct |
24 | Correct | 1 ms | 6492 KB | Output is correct |
25 | Correct | 1 ms | 6492 KB | Output is correct |
26 | Correct | 1 ms | 6492 KB | Output is correct |
27 | Correct | 1 ms | 6492 KB | Output is correct |
28 | Correct | 1 ms | 6492 KB | Output is correct |
29 | Correct | 1 ms | 6492 KB | Output is correct |
30 | Correct | 1 ms | 6492 KB | Output is correct |
31 | Correct | 1 ms | 6492 KB | Output is correct |
32 | Correct | 2 ms | 6636 KB | Output is correct |
33 | Correct | 2 ms | 6492 KB | Output is correct |
34 | Correct | 2 ms | 6492 KB | Output is correct |
35 | Correct | 2 ms | 6492 KB | Output is correct |
36 | Correct | 2 ms | 6492 KB | Output is correct |
37 | Correct | 2 ms | 6492 KB | Output is correct |
38 | Correct | 1 ms | 6492 KB | Output is correct |
39 | Correct | 1 ms | 6488 KB | Output is correct |
40 | Correct | 2 ms | 6744 KB | Output is correct |
41 | Correct | 1 ms | 6492 KB | Output is correct |
42 | Correct | 1 ms | 6492 KB | Output is correct |
43 | Correct | 1 ms | 6492 KB | Output is correct |
44 | Correct | 2 ms | 6492 KB | Output is correct |
45 | Correct | 1 ms | 6492 KB | Output is correct |
46 | Correct | 26 ms | 16244 KB | Output is correct |
47 | Correct | 24 ms | 16076 KB | Output is correct |
48 | Correct | 28 ms | 15700 KB | Output is correct |
49 | Correct | 31 ms | 16332 KB | Output is correct |
50 | Correct | 33 ms | 16840 KB | Output is correct |
51 | Correct | 33 ms | 16988 KB | Output is correct |
52 | Correct | 17 ms | 11736 KB | Output is correct |
53 | Correct | 11 ms | 9444 KB | Output is correct |
54 | Correct | 18 ms | 16120 KB | Output is correct |
55 | Correct | 35 ms | 17120 KB | Output is correct |
56 | Correct | 23 ms | 16348 KB | Output is correct |
57 | Correct | 22 ms | 16232 KB | Output is correct |
58 | Correct | 22 ms | 16600 KB | Output is correct |
59 | Correct | 29 ms | 16344 KB | Output is correct |
60 | Correct | 25 ms | 16344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 1 ms | 6488 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6492 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 1 ms | 6492 KB | Output is correct |
13 | Correct | 1 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6492 KB | Output is correct |
15 | Correct | 1 ms | 6492 KB | Output is correct |
16 | Correct | 1 ms | 6592 KB | Output is correct |
17 | Correct | 1 ms | 6492 KB | Output is correct |
18 | Correct | 1 ms | 6492 KB | Output is correct |
19 | Correct | 1 ms | 6492 KB | Output is correct |
20 | Correct | 1 ms | 6492 KB | Output is correct |
21 | Correct | 1 ms | 6492 KB | Output is correct |
22 | Correct | 1 ms | 6492 KB | Output is correct |
23 | Correct | 1 ms | 6492 KB | Output is correct |
24 | Correct | 1 ms | 6492 KB | Output is correct |
25 | Correct | 1 ms | 6492 KB | Output is correct |
26 | Correct | 1 ms | 6492 KB | Output is correct |
27 | Correct | 1 ms | 6492 KB | Output is correct |
28 | Correct | 1 ms | 6492 KB | Output is correct |
29 | Correct | 1 ms | 6492 KB | Output is correct |
30 | Correct | 1 ms | 6492 KB | Output is correct |
31 | Correct | 1 ms | 6492 KB | Output is correct |
32 | Correct | 2 ms | 6636 KB | Output is correct |
33 | Correct | 2 ms | 6492 KB | Output is correct |
34 | Correct | 2 ms | 6492 KB | Output is correct |
35 | Correct | 2 ms | 6492 KB | Output is correct |
36 | Correct | 2 ms | 6492 KB | Output is correct |
37 | Correct | 2 ms | 6492 KB | Output is correct |
38 | Correct | 1 ms | 6492 KB | Output is correct |
39 | Correct | 1 ms | 6488 KB | Output is correct |
40 | Correct | 2 ms | 6744 KB | Output is correct |
41 | Correct | 1 ms | 6492 KB | Output is correct |
42 | Correct | 1 ms | 6492 KB | Output is correct |
43 | Correct | 1 ms | 6492 KB | Output is correct |
44 | Correct | 2 ms | 6492 KB | Output is correct |
45 | Correct | 1 ms | 6492 KB | Output is correct |
46 | Correct | 26 ms | 16244 KB | Output is correct |
47 | Correct | 24 ms | 16076 KB | Output is correct |
48 | Correct | 28 ms | 15700 KB | Output is correct |
49 | Correct | 31 ms | 16332 KB | Output is correct |
50 | Correct | 33 ms | 16840 KB | Output is correct |
51 | Correct | 33 ms | 16988 KB | Output is correct |
52 | Correct | 17 ms | 11736 KB | Output is correct |
53 | Correct | 11 ms | 9444 KB | Output is correct |
54 | Correct | 18 ms | 16120 KB | Output is correct |
55 | Correct | 35 ms | 17120 KB | Output is correct |
56 | Correct | 23 ms | 16348 KB | Output is correct |
57 | Correct | 22 ms | 16232 KB | Output is correct |
58 | Correct | 22 ms | 16600 KB | Output is correct |
59 | Correct | 29 ms | 16344 KB | Output is correct |
60 | Correct | 25 ms | 16344 KB | Output is correct |
61 | Correct | 93 ms | 22988 KB | Output is correct |
62 | Correct | 105 ms | 22952 KB | Output is correct |
63 | Correct | 112 ms | 22736 KB | Output is correct |
64 | Correct | 149 ms | 21588 KB | Output is correct |
65 | Correct | 162 ms | 26716 KB | Output is correct |
66 | Correct | 169 ms | 25540 KB | Output is correct |
67 | Correct | 129 ms | 24268 KB | Output is correct |
68 | Correct | 66 ms | 18888 KB | Output is correct |
69 | Correct | 82 ms | 22976 KB | Output is correct |
70 | Correct | 163 ms | 26700 KB | Output is correct |
71 | Correct | 100 ms | 23372 KB | Output is correct |
72 | Correct | 111 ms | 23876 KB | Output is correct |
73 | Correct | 120 ms | 24772 KB | Output is correct |
74 | Correct | 126 ms | 24264 KB | Output is correct |
75 | Correct | 127 ms | 24512 KB | Output is correct |