답안 #467301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
467301 2021-08-22T12:46:17 Z theconfusedguy Bigger segments (IZhO19_segments) C++14
100 / 100
118 ms 18876 KB
#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;


typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vll;

const int mod = 1000000007;


int main(){
    SPEED;

    int N; cin >> N;
    vll arr(N+2), pref(N+2), dp(N+2);
    vi best(N+2);
    for( int i = 1; i <= N; i++ ){
        cin >> arr[i];
        pref[i] = pref[i-1] + arr[i];
    }

    for( int i = 1; i <= N; i++ ){
        best[i] = max( best[i], best[i-1] );
        dp[i] = 1 + dp[best[i]];
        lli currSum = 2 * pref[i] - pref[best[i]];
        int next = lower_bound(pref.begin() + 1, pref.begin() + N + 1, currSum ) - pref.begin();
        best[next] = max( best[next], i );
    }

    cout << dp[N] << endl;




    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 248 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 248 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 248 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 324 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 316 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 316 KB Output is correct
40 Correct 1 ms 512 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 316 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 248 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 324 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 316 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 316 KB Output is correct
40 Correct 1 ms 512 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 316 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 13 ms 3440 KB Output is correct
47 Correct 15 ms 3532 KB Output is correct
48 Correct 18 ms 3820 KB Output is correct
49 Correct 19 ms 3996 KB Output is correct
50 Correct 23 ms 4052 KB Output is correct
51 Correct 20 ms 4044 KB Output is correct
52 Correct 12 ms 2064 KB Output is correct
53 Correct 8 ms 1356 KB Output is correct
54 Correct 15 ms 3404 KB Output is correct
55 Correct 25 ms 3960 KB Output is correct
56 Correct 17 ms 3520 KB Output is correct
57 Correct 15 ms 3484 KB Output is correct
58 Correct 16 ms 3440 KB Output is correct
59 Correct 17 ms 3532 KB Output is correct
60 Correct 17 ms 3644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 248 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 324 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 316 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 316 KB Output is correct
40 Correct 1 ms 512 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 316 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 13 ms 3440 KB Output is correct
47 Correct 15 ms 3532 KB Output is correct
48 Correct 18 ms 3820 KB Output is correct
49 Correct 19 ms 3996 KB Output is correct
50 Correct 23 ms 4052 KB Output is correct
51 Correct 20 ms 4044 KB Output is correct
52 Correct 12 ms 2064 KB Output is correct
53 Correct 8 ms 1356 KB Output is correct
54 Correct 15 ms 3404 KB Output is correct
55 Correct 25 ms 3960 KB Output is correct
56 Correct 17 ms 3520 KB Output is correct
57 Correct 15 ms 3484 KB Output is correct
58 Correct 16 ms 3440 KB Output is correct
59 Correct 17 ms 3532 KB Output is correct
60 Correct 17 ms 3644 KB Output is correct
61 Correct 65 ms 15968 KB Output is correct
62 Correct 79 ms 15912 KB Output is correct
63 Correct 74 ms 16324 KB Output is correct
64 Correct 97 ms 18552 KB Output is correct
65 Correct 108 ms 18856 KB Output is correct
66 Correct 118 ms 18760 KB Output is correct
67 Correct 78 ms 15112 KB Output is correct
68 Correct 40 ms 7716 KB Output is correct
69 Correct 70 ms 15024 KB Output is correct
70 Correct 96 ms 18876 KB Output is correct
71 Correct 84 ms 15912 KB Output is correct
72 Correct 86 ms 16324 KB Output is correct
73 Correct 83 ms 16956 KB Output is correct
74 Correct 95 ms 17324 KB Output is correct
75 Correct 87 ms 17204 KB Output is correct