답안 #861716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861716 2023-10-16T17:34:14 Z Dec0Dedd Bigger segments (IZhO19_segments) C++14
100 / 100
120 ms 98284 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;

const int N = 5e5+10;
const int K = 20;
const ll INF = 1e18;

ll a[N], p[N], x[N], lg[N], st[K][N], dp[N], n;

ll que(int l, int r) {
    int i=lg[l-r+1];
    return min(st[i][l], st[i][r+(1<<i)-1]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    cin>>n;
    for (int i=1; i<=n; ++i) cin>>a[i], p[i]=p[i-1]+a[i];

    lg[1]=0;
    for (int i=2; i<N; ++i) lg[i]=lg[i/2]+1;

    for (int i=1; i<=n; ++i) {
        for (int j=0; j<K; ++j) st[j][i]=INF;
    }

    for (int j=1; j<K; ++j) st[j][1]=0;
    st[0][1]=2*p[1], dp[1]=1, x[1]=2*p[1];
    for (int i=2; i<=n; ++i) {
        int l=1, r=i-1, res=0;
        while (l <= r) {
            int m=(l+r)/2;
            if (que(i-1, m) <= p[i]) l=m+1, res=m;
            else r=m-1;
        } x[i]=p[i]-p[res]+p[i];
        dp[i]=dp[res]+1;

        st[0][i]=x[i];
        for (int j=1; j<K; ++j) {
            st[j][i]=min(st[j-1][i], i-(1<<(j-1)) >= 0 ? st[j-1][i-(1<<(j-1))] : 0);
        }
    }

    cout<<dp[n]<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 49500 KB Output is correct
2 Correct 5 ms 49496 KB Output is correct
3 Correct 5 ms 49500 KB Output is correct
4 Correct 5 ms 49708 KB Output is correct
5 Correct 5 ms 49500 KB Output is correct
6 Correct 5 ms 49500 KB Output is correct
7 Correct 6 ms 49500 KB Output is correct
8 Correct 5 ms 49500 KB Output is correct
9 Correct 5 ms 49500 KB Output is correct
10 Correct 5 ms 49500 KB Output is correct
11 Correct 5 ms 49500 KB Output is correct
12 Correct 5 ms 49500 KB Output is correct
13 Correct 5 ms 49500 KB Output is correct
14 Correct 5 ms 49500 KB Output is correct
15 Correct 5 ms 49500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 49500 KB Output is correct
2 Correct 5 ms 49496 KB Output is correct
3 Correct 5 ms 49500 KB Output is correct
4 Correct 5 ms 49708 KB Output is correct
5 Correct 5 ms 49500 KB Output is correct
6 Correct 5 ms 49500 KB Output is correct
7 Correct 6 ms 49500 KB Output is correct
8 Correct 5 ms 49500 KB Output is correct
9 Correct 5 ms 49500 KB Output is correct
10 Correct 5 ms 49500 KB Output is correct
11 Correct 5 ms 49500 KB Output is correct
12 Correct 5 ms 49500 KB Output is correct
13 Correct 5 ms 49500 KB Output is correct
14 Correct 5 ms 49500 KB Output is correct
15 Correct 5 ms 49500 KB Output is correct
16 Correct 6 ms 49500 KB Output is correct
17 Correct 5 ms 49500 KB Output is correct
18 Correct 5 ms 49684 KB Output is correct
19 Correct 6 ms 49500 KB Output is correct
20 Correct 5 ms 49500 KB Output is correct
21 Correct 6 ms 49660 KB Output is correct
22 Correct 5 ms 49500 KB Output is correct
23 Correct 5 ms 49500 KB Output is correct
24 Correct 6 ms 49932 KB Output is correct
25 Correct 6 ms 49500 KB Output is correct
26 Correct 6 ms 49500 KB Output is correct
27 Correct 5 ms 49500 KB Output is correct
28 Correct 5 ms 49500 KB Output is correct
29 Correct 5 ms 49500 KB Output is correct
30 Correct 5 ms 49696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 49500 KB Output is correct
2 Correct 5 ms 49496 KB Output is correct
3 Correct 5 ms 49500 KB Output is correct
4 Correct 5 ms 49708 KB Output is correct
5 Correct 5 ms 49500 KB Output is correct
6 Correct 5 ms 49500 KB Output is correct
7 Correct 6 ms 49500 KB Output is correct
8 Correct 5 ms 49500 KB Output is correct
9 Correct 5 ms 49500 KB Output is correct
10 Correct 5 ms 49500 KB Output is correct
11 Correct 5 ms 49500 KB Output is correct
12 Correct 5 ms 49500 KB Output is correct
13 Correct 5 ms 49500 KB Output is correct
14 Correct 5 ms 49500 KB Output is correct
15 Correct 5 ms 49500 KB Output is correct
16 Correct 6 ms 49500 KB Output is correct
17 Correct 5 ms 49500 KB Output is correct
18 Correct 5 ms 49684 KB Output is correct
19 Correct 6 ms 49500 KB Output is correct
20 Correct 5 ms 49500 KB Output is correct
21 Correct 6 ms 49660 KB Output is correct
22 Correct 5 ms 49500 KB Output is correct
23 Correct 5 ms 49500 KB Output is correct
24 Correct 6 ms 49932 KB Output is correct
25 Correct 6 ms 49500 KB Output is correct
26 Correct 6 ms 49500 KB Output is correct
27 Correct 5 ms 49500 KB Output is correct
28 Correct 5 ms 49500 KB Output is correct
29 Correct 5 ms 49500 KB Output is correct
30 Correct 5 ms 49696 KB Output is correct
31 Correct 6 ms 49756 KB Output is correct
32 Correct 6 ms 49580 KB Output is correct
33 Correct 6 ms 49756 KB Output is correct
34 Correct 7 ms 49756 KB Output is correct
35 Correct 6 ms 49712 KB Output is correct
36 Correct 6 ms 49752 KB Output is correct
37 Correct 6 ms 49756 KB Output is correct
38 Correct 6 ms 49756 KB Output is correct
39 Correct 6 ms 49756 KB Output is correct
40 Correct 6 ms 49756 KB Output is correct
41 Correct 6 ms 49756 KB Output is correct
42 Correct 6 ms 49756 KB Output is correct
43 Correct 6 ms 49756 KB Output is correct
44 Correct 6 ms 49756 KB Output is correct
45 Correct 6 ms 49752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 49500 KB Output is correct
2 Correct 5 ms 49496 KB Output is correct
3 Correct 5 ms 49500 KB Output is correct
4 Correct 5 ms 49708 KB Output is correct
5 Correct 5 ms 49500 KB Output is correct
6 Correct 5 ms 49500 KB Output is correct
7 Correct 6 ms 49500 KB Output is correct
8 Correct 5 ms 49500 KB Output is correct
9 Correct 5 ms 49500 KB Output is correct
10 Correct 5 ms 49500 KB Output is correct
11 Correct 5 ms 49500 KB Output is correct
12 Correct 5 ms 49500 KB Output is correct
13 Correct 5 ms 49500 KB Output is correct
14 Correct 5 ms 49500 KB Output is correct
15 Correct 5 ms 49500 KB Output is correct
16 Correct 6 ms 49500 KB Output is correct
17 Correct 5 ms 49500 KB Output is correct
18 Correct 5 ms 49684 KB Output is correct
19 Correct 6 ms 49500 KB Output is correct
20 Correct 5 ms 49500 KB Output is correct
21 Correct 6 ms 49660 KB Output is correct
22 Correct 5 ms 49500 KB Output is correct
23 Correct 5 ms 49500 KB Output is correct
24 Correct 6 ms 49932 KB Output is correct
25 Correct 6 ms 49500 KB Output is correct
26 Correct 6 ms 49500 KB Output is correct
27 Correct 5 ms 49500 KB Output is correct
28 Correct 5 ms 49500 KB Output is correct
29 Correct 5 ms 49500 KB Output is correct
30 Correct 5 ms 49696 KB Output is correct
31 Correct 6 ms 49756 KB Output is correct
32 Correct 6 ms 49580 KB Output is correct
33 Correct 6 ms 49756 KB Output is correct
34 Correct 7 ms 49756 KB Output is correct
35 Correct 6 ms 49712 KB Output is correct
36 Correct 6 ms 49752 KB Output is correct
37 Correct 6 ms 49756 KB Output is correct
38 Correct 6 ms 49756 KB Output is correct
39 Correct 6 ms 49756 KB Output is correct
40 Correct 6 ms 49756 KB Output is correct
41 Correct 6 ms 49756 KB Output is correct
42 Correct 6 ms 49756 KB Output is correct
43 Correct 6 ms 49756 KB Output is correct
44 Correct 6 ms 49756 KB Output is correct
45 Correct 6 ms 49752 KB Output is correct
46 Correct 21 ms 72796 KB Output is correct
47 Correct 25 ms 72924 KB Output is correct
48 Correct 23 ms 72792 KB Output is correct
49 Correct 23 ms 72784 KB Output is correct
50 Correct 23 ms 72796 KB Output is correct
51 Correct 24 ms 72872 KB Output is correct
52 Correct 14 ms 60508 KB Output is correct
53 Correct 10 ms 56272 KB Output is correct
54 Correct 21 ms 72792 KB Output is correct
55 Correct 24 ms 72900 KB Output is correct
56 Correct 21 ms 72796 KB Output is correct
57 Correct 24 ms 72796 KB Output is correct
58 Correct 21 ms 72792 KB Output is correct
59 Correct 21 ms 72796 KB Output is correct
60 Correct 21 ms 72792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 49500 KB Output is correct
2 Correct 5 ms 49496 KB Output is correct
3 Correct 5 ms 49500 KB Output is correct
4 Correct 5 ms 49708 KB Output is correct
5 Correct 5 ms 49500 KB Output is correct
6 Correct 5 ms 49500 KB Output is correct
7 Correct 6 ms 49500 KB Output is correct
8 Correct 5 ms 49500 KB Output is correct
9 Correct 5 ms 49500 KB Output is correct
10 Correct 5 ms 49500 KB Output is correct
11 Correct 5 ms 49500 KB Output is correct
12 Correct 5 ms 49500 KB Output is correct
13 Correct 5 ms 49500 KB Output is correct
14 Correct 5 ms 49500 KB Output is correct
15 Correct 5 ms 49500 KB Output is correct
16 Correct 6 ms 49500 KB Output is correct
17 Correct 5 ms 49500 KB Output is correct
18 Correct 5 ms 49684 KB Output is correct
19 Correct 6 ms 49500 KB Output is correct
20 Correct 5 ms 49500 KB Output is correct
21 Correct 6 ms 49660 KB Output is correct
22 Correct 5 ms 49500 KB Output is correct
23 Correct 5 ms 49500 KB Output is correct
24 Correct 6 ms 49932 KB Output is correct
25 Correct 6 ms 49500 KB Output is correct
26 Correct 6 ms 49500 KB Output is correct
27 Correct 5 ms 49500 KB Output is correct
28 Correct 5 ms 49500 KB Output is correct
29 Correct 5 ms 49500 KB Output is correct
30 Correct 5 ms 49696 KB Output is correct
31 Correct 6 ms 49756 KB Output is correct
32 Correct 6 ms 49580 KB Output is correct
33 Correct 6 ms 49756 KB Output is correct
34 Correct 7 ms 49756 KB Output is correct
35 Correct 6 ms 49712 KB Output is correct
36 Correct 6 ms 49752 KB Output is correct
37 Correct 6 ms 49756 KB Output is correct
38 Correct 6 ms 49756 KB Output is correct
39 Correct 6 ms 49756 KB Output is correct
40 Correct 6 ms 49756 KB Output is correct
41 Correct 6 ms 49756 KB Output is correct
42 Correct 6 ms 49756 KB Output is correct
43 Correct 6 ms 49756 KB Output is correct
44 Correct 6 ms 49756 KB Output is correct
45 Correct 6 ms 49752 KB Output is correct
46 Correct 21 ms 72796 KB Output is correct
47 Correct 25 ms 72924 KB Output is correct
48 Correct 23 ms 72792 KB Output is correct
49 Correct 23 ms 72784 KB Output is correct
50 Correct 23 ms 72796 KB Output is correct
51 Correct 24 ms 72872 KB Output is correct
52 Correct 14 ms 60508 KB Output is correct
53 Correct 10 ms 56272 KB Output is correct
54 Correct 21 ms 72792 KB Output is correct
55 Correct 24 ms 72900 KB Output is correct
56 Correct 21 ms 72796 KB Output is correct
57 Correct 24 ms 72796 KB Output is correct
58 Correct 21 ms 72792 KB Output is correct
59 Correct 21 ms 72796 KB Output is correct
60 Correct 21 ms 72792 KB Output is correct
61 Correct 101 ms 98284 KB Output is correct
62 Correct 105 ms 98132 KB Output is correct
63 Correct 109 ms 98128 KB Output is correct
64 Correct 107 ms 98260 KB Output is correct
65 Correct 114 ms 98284 KB Output is correct
66 Correct 120 ms 98228 KB Output is correct
67 Correct 86 ms 96680 KB Output is correct
68 Correct 45 ms 91224 KB Output is correct
69 Correct 97 ms 98228 KB Output is correct
70 Correct 107 ms 98148 KB Output is correct
71 Correct 90 ms 98256 KB Output is correct
72 Correct 99 ms 98220 KB Output is correct
73 Correct 96 ms 98132 KB Output is correct
74 Correct 112 ms 98032 KB Output is correct
75 Correct 95 ms 98204 KB Output is correct