답안 #497581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497581 2021-12-23T10:11:57 Z ergagan Bigger segments (IZhO19_segments) C++17
100 / 100
75 ms 16324 KB
//я так много думал, что опять попал
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define f first
#define s second
#define left(v) v + v
#define right(v) v + v + 1
#define ub upper_bound
#define lb lower_bound
#define pll pair<ll,ll>


//17 SEVENTEEN
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;

const long double Pi = acos(-1.0);
const ll dx[] = {0,0,1,-1};
const ll dy[] = {1,-1,0,0};
const ll N = (ll) 1e6 + 17;
const ll M = (ll) 5e3 + 69;
const ll inf = (ll) 1e14 + 3;
const ll mod = (ll) 1e9 + 7;
ll sq(ll x) { return x * x; }

ll zxc = 1, a[N], p[N];

pll dp[N];

void solve() {
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i++) {
        cin >> a[i];
        p[i] = p[i - 1] + a[i];
        dp[i] = {1, 0};
    }
    for(ll i = 1; i <= n; i++) {
        dp[i] = max(dp[i], dp[i - 1]);

        ll l = i + 1, r = n + 1;
        while(l < r) {
            ll m = (l + r) / 2;
            if(p[m] >= 2 * p[i] - p[dp[i].s]) r = m;
            else l = m + 1;
        }
        if(l <= n) dp[l] = max(dp[l], {dp[i].f + 1, i});
    }
    cout << dp[n].f;
}

int main(/*Уверенно*/) {
ios_base::sync_with_stdio(0);
    cin.tie(0);
/*
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
*/
//    cin >> zxc;
    while(zxc--) {
        solve();
    }
  	return 0;
}
// さよならさ いかなくちゃ
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 1 ms 312 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 408 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 328 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 324 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 324 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 328 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 1 ms 312 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 408 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 328 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 324 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 324 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 328 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 11 ms 3572 KB Output is correct
47 Correct 12 ms 3520 KB Output is correct
48 Correct 14 ms 3620 KB Output is correct
49 Correct 15 ms 3692 KB Output is correct
50 Correct 12 ms 3652 KB Output is correct
51 Correct 14 ms 3712 KB Output is correct
52 Correct 7 ms 1920 KB Output is correct
53 Correct 5 ms 1352 KB Output is correct
54 Correct 10 ms 3532 KB Output is correct
55 Correct 13 ms 3692 KB Output is correct
56 Correct 9 ms 3536 KB Output is correct
57 Correct 11 ms 3492 KB Output is correct
58 Correct 11 ms 3476 KB Output is correct
59 Correct 11 ms 3632 KB Output is correct
60 Correct 10 ms 3620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 1 ms 312 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 408 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 328 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 324 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 324 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 328 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 11 ms 3572 KB Output is correct
47 Correct 12 ms 3520 KB Output is correct
48 Correct 14 ms 3620 KB Output is correct
49 Correct 15 ms 3692 KB Output is correct
50 Correct 12 ms 3652 KB Output is correct
51 Correct 14 ms 3712 KB Output is correct
52 Correct 7 ms 1920 KB Output is correct
53 Correct 5 ms 1352 KB Output is correct
54 Correct 10 ms 3532 KB Output is correct
55 Correct 13 ms 3692 KB Output is correct
56 Correct 9 ms 3536 KB Output is correct
57 Correct 11 ms 3492 KB Output is correct
58 Correct 11 ms 3476 KB Output is correct
59 Correct 11 ms 3632 KB Output is correct
60 Correct 10 ms 3620 KB Output is correct
61 Correct 50 ms 16264 KB Output is correct
62 Correct 53 ms 16216 KB Output is correct
63 Correct 60 ms 16192 KB Output is correct
64 Correct 75 ms 16264 KB Output is correct
65 Correct 57 ms 16224 KB Output is correct
66 Correct 72 ms 16192 KB Output is correct
67 Correct 53 ms 13080 KB Output is correct
68 Correct 27 ms 6780 KB Output is correct
69 Correct 49 ms 16252 KB Output is correct
70 Correct 66 ms 16264 KB Output is correct
71 Correct 41 ms 16196 KB Output is correct
72 Correct 48 ms 16324 KB Output is correct
73 Correct 49 ms 16196 KB Output is correct
74 Correct 48 ms 16168 KB Output is correct
75 Correct 48 ms 16188 KB Output is correct