답안 #860994

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
860994 2023-10-15T04:46:07 Z Cookie Bigger segments (IZhO19_segments) C++14
100 / 100
86 ms 48152 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define vt vector
#define pb push_back
#define pii pair<int, int>
#define sz(dq) (int)dq.size()
#define forr(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pll pair<ll, ll>
ifstream fin("store.inp");
ofstream fout("store.out");
const ll mxn = 5e5 + 5, inf = 1e9, mod = 1e9 + 7, sq = 800, mxv = 1e6 + 5, pr = 37, mod2 = 1e9 + 9, mod3 = 998244353;
//const int x[4] = {0, -1, 0, 1};
int n;
pll dp[mxn + 1];
ll a[mxn + 1], pref[mxn + 1];
vt<pll>events[mxn + 1];
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i]; pref[i] = pref[i - 1] + a[i];
    }
    dp[0] = make_pair(0, 0);
    pair<ll, ll>mx = make_pair(0, 0);
    for(int i = 1; i <= n; i++){
        for(auto j: events[i]){
            mx = max(mx, j);
        }
        dp[i] = make_pair(mx.first + 1, pref[i] - pref[mx.second]);
        int l = i + 1, r = n, ans = n + 1;
        while(l <= r){
            int mid = (l + r) >> 1;
            if(pref[mid] - pref[i] >= pref[i] - pref[mx.second]){
                ans = mid; r = mid - 1;
            }else{
                l = mid + 1;
            }
        }
        events[ans].pb(make_pair(dp[i].first, i));
        
    }
    cout << dp[n].first;
    return(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 3 ms 16984 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16984 KB Output is correct
11 Correct 3 ms 16984 KB Output is correct
12 Correct 3 ms 16904 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 3 ms 16984 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16984 KB Output is correct
11 Correct 3 ms 16984 KB Output is correct
12 Correct 3 ms 16904 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
16 Correct 3 ms 16988 KB Output is correct
17 Correct 3 ms 16988 KB Output is correct
18 Correct 3 ms 16988 KB Output is correct
19 Correct 3 ms 16988 KB Output is correct
20 Correct 3 ms 16988 KB Output is correct
21 Correct 3 ms 16988 KB Output is correct
22 Correct 3 ms 16988 KB Output is correct
23 Correct 3 ms 16988 KB Output is correct
24 Correct 3 ms 16988 KB Output is correct
25 Correct 3 ms 16984 KB Output is correct
26 Correct 4 ms 17056 KB Output is correct
27 Correct 3 ms 16988 KB Output is correct
28 Correct 3 ms 17056 KB Output is correct
29 Correct 4 ms 16988 KB Output is correct
30 Correct 3 ms 16988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 3 ms 16984 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16984 KB Output is correct
11 Correct 3 ms 16984 KB Output is correct
12 Correct 3 ms 16904 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
16 Correct 3 ms 16988 KB Output is correct
17 Correct 3 ms 16988 KB Output is correct
18 Correct 3 ms 16988 KB Output is correct
19 Correct 3 ms 16988 KB Output is correct
20 Correct 3 ms 16988 KB Output is correct
21 Correct 3 ms 16988 KB Output is correct
22 Correct 3 ms 16988 KB Output is correct
23 Correct 3 ms 16988 KB Output is correct
24 Correct 3 ms 16988 KB Output is correct
25 Correct 3 ms 16984 KB Output is correct
26 Correct 4 ms 17056 KB Output is correct
27 Correct 3 ms 16988 KB Output is correct
28 Correct 3 ms 17056 KB Output is correct
29 Correct 4 ms 16988 KB Output is correct
30 Correct 3 ms 16988 KB Output is correct
31 Correct 3 ms 16988 KB Output is correct
32 Correct 4 ms 16988 KB Output is correct
33 Correct 4 ms 16988 KB Output is correct
34 Correct 4 ms 16988 KB Output is correct
35 Correct 3 ms 16984 KB Output is correct
36 Correct 4 ms 16988 KB Output is correct
37 Correct 4 ms 16988 KB Output is correct
38 Correct 4 ms 16988 KB Output is correct
39 Correct 4 ms 17020 KB Output is correct
40 Correct 3 ms 16988 KB Output is correct
41 Correct 4 ms 17500 KB Output is correct
42 Correct 3 ms 17060 KB Output is correct
43 Correct 3 ms 16988 KB Output is correct
44 Correct 3 ms 16984 KB Output is correct
45 Correct 4 ms 16988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 3 ms 16984 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16984 KB Output is correct
11 Correct 3 ms 16984 KB Output is correct
12 Correct 3 ms 16904 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
16 Correct 3 ms 16988 KB Output is correct
17 Correct 3 ms 16988 KB Output is correct
18 Correct 3 ms 16988 KB Output is correct
19 Correct 3 ms 16988 KB Output is correct
20 Correct 3 ms 16988 KB Output is correct
21 Correct 3 ms 16988 KB Output is correct
22 Correct 3 ms 16988 KB Output is correct
23 Correct 3 ms 16988 KB Output is correct
24 Correct 3 ms 16988 KB Output is correct
25 Correct 3 ms 16984 KB Output is correct
26 Correct 4 ms 17056 KB Output is correct
27 Correct 3 ms 16988 KB Output is correct
28 Correct 3 ms 17056 KB Output is correct
29 Correct 4 ms 16988 KB Output is correct
30 Correct 3 ms 16988 KB Output is correct
31 Correct 3 ms 16988 KB Output is correct
32 Correct 4 ms 16988 KB Output is correct
33 Correct 4 ms 16988 KB Output is correct
34 Correct 4 ms 16988 KB Output is correct
35 Correct 3 ms 16984 KB Output is correct
36 Correct 4 ms 16988 KB Output is correct
37 Correct 4 ms 16988 KB Output is correct
38 Correct 4 ms 16988 KB Output is correct
39 Correct 4 ms 17020 KB Output is correct
40 Correct 3 ms 16988 KB Output is correct
41 Correct 4 ms 17500 KB Output is correct
42 Correct 3 ms 17060 KB Output is correct
43 Correct 3 ms 16988 KB Output is correct
44 Correct 3 ms 16984 KB Output is correct
45 Correct 4 ms 16988 KB Output is correct
46 Correct 12 ms 23156 KB Output is correct
47 Correct 17 ms 24176 KB Output is correct
48 Correct 22 ms 24660 KB Output is correct
49 Correct 17 ms 25176 KB Output is correct
50 Correct 17 ms 25180 KB Output is correct
51 Correct 21 ms 24668 KB Output is correct
52 Correct 12 ms 18828 KB Output is correct
53 Correct 8 ms 18008 KB Output is correct
54 Correct 17 ms 23900 KB Output is correct
55 Correct 19 ms 24916 KB Output is correct
56 Correct 14 ms 24668 KB Output is correct
57 Correct 14 ms 24044 KB Output is correct
58 Correct 15 ms 24276 KB Output is correct
59 Correct 15 ms 24664 KB Output is correct
60 Correct 15 ms 24664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 3 ms 16984 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16984 KB Output is correct
11 Correct 3 ms 16984 KB Output is correct
12 Correct 3 ms 16904 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
16 Correct 3 ms 16988 KB Output is correct
17 Correct 3 ms 16988 KB Output is correct
18 Correct 3 ms 16988 KB Output is correct
19 Correct 3 ms 16988 KB Output is correct
20 Correct 3 ms 16988 KB Output is correct
21 Correct 3 ms 16988 KB Output is correct
22 Correct 3 ms 16988 KB Output is correct
23 Correct 3 ms 16988 KB Output is correct
24 Correct 3 ms 16988 KB Output is correct
25 Correct 3 ms 16984 KB Output is correct
26 Correct 4 ms 17056 KB Output is correct
27 Correct 3 ms 16988 KB Output is correct
28 Correct 3 ms 17056 KB Output is correct
29 Correct 4 ms 16988 KB Output is correct
30 Correct 3 ms 16988 KB Output is correct
31 Correct 3 ms 16988 KB Output is correct
32 Correct 4 ms 16988 KB Output is correct
33 Correct 4 ms 16988 KB Output is correct
34 Correct 4 ms 16988 KB Output is correct
35 Correct 3 ms 16984 KB Output is correct
36 Correct 4 ms 16988 KB Output is correct
37 Correct 4 ms 16988 KB Output is correct
38 Correct 4 ms 16988 KB Output is correct
39 Correct 4 ms 17020 KB Output is correct
40 Correct 3 ms 16988 KB Output is correct
41 Correct 4 ms 17500 KB Output is correct
42 Correct 3 ms 17060 KB Output is correct
43 Correct 3 ms 16988 KB Output is correct
44 Correct 3 ms 16984 KB Output is correct
45 Correct 4 ms 16988 KB Output is correct
46 Correct 12 ms 23156 KB Output is correct
47 Correct 17 ms 24176 KB Output is correct
48 Correct 22 ms 24660 KB Output is correct
49 Correct 17 ms 25176 KB Output is correct
50 Correct 17 ms 25180 KB Output is correct
51 Correct 21 ms 24668 KB Output is correct
52 Correct 12 ms 18828 KB Output is correct
53 Correct 8 ms 18008 KB Output is correct
54 Correct 17 ms 23900 KB Output is correct
55 Correct 19 ms 24916 KB Output is correct
56 Correct 14 ms 24668 KB Output is correct
57 Correct 14 ms 24044 KB Output is correct
58 Correct 15 ms 24276 KB Output is correct
59 Correct 15 ms 24664 KB Output is correct
60 Correct 15 ms 24664 KB Output is correct
61 Correct 41 ms 37564 KB Output is correct
62 Correct 53 ms 39496 KB Output is correct
63 Correct 71 ms 42128 KB Output is correct
64 Correct 76 ms 46160 KB Output is correct
65 Correct 69 ms 48152 KB Output is correct
66 Correct 86 ms 45836 KB Output is correct
67 Correct 69 ms 41552 KB Output is correct
68 Correct 36 ms 30348 KB Output is correct
69 Correct 71 ms 42068 KB Output is correct
70 Correct 75 ms 47172 KB Output is correct
71 Correct 55 ms 45208 KB Output is correct
72 Correct 59 ms 42708 KB Output is correct
73 Correct 62 ms 45256 KB Output is correct
74 Correct 63 ms 46736 KB Output is correct
75 Correct 63 ms 46740 KB Output is correct