답안 #685074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685074 2023-01-23T09:13:02 Z gagik_2007 Bigger segments (IZhO19_segments) C++17
37 / 100
214 ms 93100 KB
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <chrono>
#include <ctime>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <limits>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <functional>
#include <random>
#include <cassert>
using namespace std;

typedef long long ll;
typedef long double ld;

#define ff first
#define ss second

ll ttt;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll N = 3007;
ll n, m, k;
ll a[N];
ll dp[N][N];
ll pf[N];
ll sf[N][N];
ll t[N][4 * N];

void build(int v, int tl, int tr, int i) {
    if (tl == tr) {
        t[i][v] = 0;
    }
    else {
        int tm = (tl + tr) / 2;
        build(2 * v, tl, tm, i);
        build(2 * v + 1, tm + 1, tr, i);
        t[i][v] = max(t[i][2 * v], t[i][2 * v + 1]);
    }
}

void update(int v, int tl, int tr, int ind, ll val, int i) {
    if (tl == tr) {
        t[i][v] = val;
    }
    else {
        int tm = (tl + tr) / 2;
        if (ind <= tm) {
            update(2 * v, tl, tm, ind, val, i);
        }
        else {
            update(2 * v + 1, tm + 1, tr, ind, val, i);
        }
        t[i][v] = max(t[i][2 * v], t[i][2 * v + 1]);
    }
}

ll get_max(int v, int tl, int tr, int l, int r, int i) {
    if (l > r)return -MOD;
    if (tl == l && tr == r) {
        return t[i][v];
    }
    else {
        int tm = (tl + tr) / 2;
        return max(get_max(2 * v, tl, tm, l, min(r, tm), i),
            get_max(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, i));
    }
}

ll pref(int l, int r) {
    if (l == 0)return pf[r];
    return pf[r] - pf[l - 1];
}

int find_ind(ll sum, int j) {
    if (a[j] > sum) {
        return -1;
    }
    int l = 0, r = j;
    while (r > l) {
        int mid = (l + r) / 2;
        if (pref(mid, j) <= sum) {
            r = mid;
        }
        else {
            l = mid + 1;
        }
    }
    return l;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i == 0)pf[i] = a[i];
        else pf[i] = pf[i - 1] + a[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0) {
                dp[i][j] = 1;
            }
            else {
                int p = find_ind(pref(j, i), j - 1);
                if (p == -1) {
                    dp[i][j] = -MOD;
                }
                else {
                    //cout << p << ", " << j - 1 << ": ";
                    dp[i][j] = sf[j - 1][p] + 1;
                }
            }
            //cout << dp[i][j] << " ";
        }
        //cout << endl;
        sf[i][i] = dp[i][i];
        for (int j = i - 1; j >= 0; j--) {
            sf[i][j] = max(sf[i][j + 1], dp[i][j]);
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, dp[n - 1][i]);
    }
    cout << ans << endl;
    return 0;
}

/// ---- - --------  ------ -------- -- - - -
/// Just a reminder. Ubuntu password is I O I
/// ---- - --------  ------ -------- -- - - -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 6 ms 6308 KB Output is correct
17 Correct 5 ms 6228 KB Output is correct
18 Correct 6 ms 6228 KB Output is correct
19 Correct 6 ms 6228 KB Output is correct
20 Correct 5 ms 6228 KB Output is correct
21 Correct 6 ms 6228 KB Output is correct
22 Correct 4 ms 4728 KB Output is correct
23 Correct 3 ms 3412 KB Output is correct
24 Correct 7 ms 6228 KB Output is correct
25 Correct 6 ms 6228 KB Output is correct
26 Correct 5 ms 6228 KB Output is correct
27 Correct 5 ms 6228 KB Output is correct
28 Correct 5 ms 6228 KB Output is correct
29 Correct 5 ms 6228 KB Output is correct
30 Correct 5 ms 6228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 6 ms 6308 KB Output is correct
17 Correct 5 ms 6228 KB Output is correct
18 Correct 6 ms 6228 KB Output is correct
19 Correct 6 ms 6228 KB Output is correct
20 Correct 5 ms 6228 KB Output is correct
21 Correct 6 ms 6228 KB Output is correct
22 Correct 4 ms 4728 KB Output is correct
23 Correct 3 ms 3412 KB Output is correct
24 Correct 7 ms 6228 KB Output is correct
25 Correct 6 ms 6228 KB Output is correct
26 Correct 5 ms 6228 KB Output is correct
27 Correct 5 ms 6228 KB Output is correct
28 Correct 5 ms 6228 KB Output is correct
29 Correct 5 ms 6228 KB Output is correct
30 Correct 5 ms 6228 KB Output is correct
31 Correct 199 ms 92960 KB Output is correct
32 Correct 174 ms 92912 KB Output is correct
33 Correct 195 ms 93032 KB Output is correct
34 Correct 193 ms 93100 KB Output is correct
35 Correct 197 ms 93004 KB Output is correct
36 Correct 198 ms 92860 KB Output is correct
37 Correct 136 ms 69344 KB Output is correct
38 Correct 86 ms 47728 KB Output is correct
39 Correct 191 ms 92876 KB Output is correct
40 Correct 195 ms 92940 KB Output is correct
41 Correct 193 ms 92884 KB Output is correct
42 Correct 185 ms 92948 KB Output is correct
43 Correct 214 ms 93040 KB Output is correct
44 Correct 180 ms 92872 KB Output is correct
45 Correct 181 ms 92980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 6 ms 6308 KB Output is correct
17 Correct 5 ms 6228 KB Output is correct
18 Correct 6 ms 6228 KB Output is correct
19 Correct 6 ms 6228 KB Output is correct
20 Correct 5 ms 6228 KB Output is correct
21 Correct 6 ms 6228 KB Output is correct
22 Correct 4 ms 4728 KB Output is correct
23 Correct 3 ms 3412 KB Output is correct
24 Correct 7 ms 6228 KB Output is correct
25 Correct 6 ms 6228 KB Output is correct
26 Correct 5 ms 6228 KB Output is correct
27 Correct 5 ms 6228 KB Output is correct
28 Correct 5 ms 6228 KB Output is correct
29 Correct 5 ms 6228 KB Output is correct
30 Correct 5 ms 6228 KB Output is correct
31 Correct 199 ms 92960 KB Output is correct
32 Correct 174 ms 92912 KB Output is correct
33 Correct 195 ms 93032 KB Output is correct
34 Correct 193 ms 93100 KB Output is correct
35 Correct 197 ms 93004 KB Output is correct
36 Correct 198 ms 92860 KB Output is correct
37 Correct 136 ms 69344 KB Output is correct
38 Correct 86 ms 47728 KB Output is correct
39 Correct 191 ms 92876 KB Output is correct
40 Correct 195 ms 92940 KB Output is correct
41 Correct 193 ms 92884 KB Output is correct
42 Correct 185 ms 92948 KB Output is correct
43 Correct 214 ms 93040 KB Output is correct
44 Correct 180 ms 92872 KB Output is correct
45 Correct 181 ms 92980 KB Output is correct
46 Correct 2 ms 2772 KB Output is correct
47 Incorrect 105 ms 56268 KB Output isn't correct
48 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 6 ms 6308 KB Output is correct
17 Correct 5 ms 6228 KB Output is correct
18 Correct 6 ms 6228 KB Output is correct
19 Correct 6 ms 6228 KB Output is correct
20 Correct 5 ms 6228 KB Output is correct
21 Correct 6 ms 6228 KB Output is correct
22 Correct 4 ms 4728 KB Output is correct
23 Correct 3 ms 3412 KB Output is correct
24 Correct 7 ms 6228 KB Output is correct
25 Correct 6 ms 6228 KB Output is correct
26 Correct 5 ms 6228 KB Output is correct
27 Correct 5 ms 6228 KB Output is correct
28 Correct 5 ms 6228 KB Output is correct
29 Correct 5 ms 6228 KB Output is correct
30 Correct 5 ms 6228 KB Output is correct
31 Correct 199 ms 92960 KB Output is correct
32 Correct 174 ms 92912 KB Output is correct
33 Correct 195 ms 93032 KB Output is correct
34 Correct 193 ms 93100 KB Output is correct
35 Correct 197 ms 93004 KB Output is correct
36 Correct 198 ms 92860 KB Output is correct
37 Correct 136 ms 69344 KB Output is correct
38 Correct 86 ms 47728 KB Output is correct
39 Correct 191 ms 92876 KB Output is correct
40 Correct 195 ms 92940 KB Output is correct
41 Correct 193 ms 92884 KB Output is correct
42 Correct 185 ms 92948 KB Output is correct
43 Correct 214 ms 93040 KB Output is correct
44 Correct 180 ms 92872 KB Output is correct
45 Correct 181 ms 92980 KB Output is correct
46 Correct 2 ms 2772 KB Output is correct
47 Incorrect 105 ms 56268 KB Output isn't correct
48 Halted 0 ms 0 KB -