답안 #407425

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
407425 2021-05-18T23:53:35 Z 534351 Cigle (COI21_cigle) C++17
48 / 100
1000 ms 64200 KB
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()

const int MAXN = 5013;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N;
int arr[MAXN], pref[MAXN];
int dp[MAXN][MAXN];
int ans;
int seg[4 * MAXN], lazy[4 * MAXN];

void build(int w, int L, int R, int k)
{
    lazy[w] = 0;
    if (L == R)
    {
        seg[w] = dp[L][k];
        return;
    }
    int mid = (L + R) >> 1;;
    build(w << 1, L, mid, k);
    build(w << 1 | 1, mid + 1, R, k);
    seg[w] = max(seg[w << 1], seg[w << 1 | 1]);
}
void push(int w, int L, int R)
{
    if (!lazy[w]) return;
    seg[w] += lazy[w];
    if (L != R)
    {
        lazy[w << 1] += lazy[w];
        lazy[w << 1 | 1] += lazy[w];
    }
    lazy[w] = 0;
    return;
}
void update(int w, int L, int R, int a, int b)
{
    push(w, L, R);
    if (b < L || R < a)
    {
        return;
    }
    if (a <= L && R <= b)
    {
        lazy[w]++;
        push(w, L, R);
        return;
    }
    int mid = (L + R) >> 1;
    update(w << 1, L, mid, a, b);
    update(w << 1 | 1, mid + 1, R, a, b);
    seg[w] = max(seg[w << 1], seg[w << 1 | 1]);
}

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    cin >> N;
    FOR(i, 0, N)
    {
        cin >> arr[i];
        pref[i + 1] = pref[i] + arr[i];
    }
    // dp[0][0] = 0;
    FOR(i, 1, N + 1)
    {
        int iter = i - 1;
        FOR(j, i, N + 1)
        {
            // dp[i][j] = 0;
            // FOR(k, 1, i)
            // {
            //     ckmax(dp[i][j], dp[k][i - 1]);
            // }
            dp[i][j] = seg[1];
            int c = 2 * pref[i - 1] - pref[j];
            while(iter != 0 && pref[iter] > c)
            {
                iter--;
            }
            // cerr << "dp " << i << ' ' << j << " = " << dp[i][j] << endl;
            if (pref[iter] == c)
            {
                // FOR(k, 1, iter + 1)
                // {
                //     // cerr << "ADD " << k << ' ' << i - 1 << endl;
                //     dp[k][i - 1]++;
                // }
                update(1, 1, i - 1, 1, iter);
            }
            //i...j. that means you use i-1....j-1.
            //count how many s i-2...k = si-1...c
            //pref[i-1] - pref[k] = pref[j] - pref[i - 1].
            //pref[k] = 2 pref[i - 1] - pref[j]
            //find dp[i][j].
            //dp[i][j] = max(dp[i][j], dp[k][i - 1] + c(k, i, j))
            //c(k, i, j) is # of positions l such that s[k] +
            //there's always some poition
        }
        build(1, 1, i, i);
    }
    FOR(i, 1, N + 1)
    {
        ckmax(ans, dp[i][N]);
    }
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 704 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2764 KB Output is correct
2 Correct 11 ms 2764 KB Output is correct
3 Correct 9 ms 2764 KB Output is correct
4 Correct 10 ms 2764 KB Output is correct
5 Correct 10 ms 2788 KB Output is correct
6 Correct 10 ms 2764 KB Output is correct
7 Correct 10 ms 2764 KB Output is correct
8 Correct 10 ms 2764 KB Output is correct
9 Correct 10 ms 2764 KB Output is correct
10 Correct 10 ms 2832 KB Output is correct
11 Correct 11 ms 2776 KB Output is correct
12 Correct 9 ms 2764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 704 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 8 ms 2764 KB Output is correct
22 Correct 11 ms 2764 KB Output is correct
23 Correct 9 ms 2764 KB Output is correct
24 Correct 10 ms 2764 KB Output is correct
25 Correct 10 ms 2788 KB Output is correct
26 Correct 10 ms 2764 KB Output is correct
27 Correct 10 ms 2764 KB Output is correct
28 Correct 10 ms 2764 KB Output is correct
29 Correct 10 ms 2764 KB Output is correct
30 Correct 10 ms 2832 KB Output is correct
31 Correct 11 ms 2776 KB Output is correct
32 Correct 9 ms 2764 KB Output is correct
33 Correct 8 ms 2760 KB Output is correct
34 Correct 9 ms 2828 KB Output is correct
35 Correct 10 ms 2740 KB Output is correct
36 Correct 10 ms 2816 KB Output is correct
37 Correct 10 ms 2804 KB Output is correct
38 Correct 10 ms 2860 KB Output is correct
39 Correct 7 ms 2764 KB Output is correct
40 Correct 5 ms 2764 KB Output is correct
41 Correct 5 ms 2764 KB Output is correct
42 Correct 5 ms 2764 KB Output is correct
43 Correct 5 ms 2764 KB Output is correct
44 Correct 5 ms 2740 KB Output is correct
45 Correct 5 ms 2764 KB Output is correct
46 Correct 5 ms 2764 KB Output is correct
47 Correct 5 ms 2764 KB Output is correct
48 Correct 5 ms 2764 KB Output is correct
49 Correct 5 ms 2764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 704 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 8 ms 2764 KB Output is correct
22 Correct 11 ms 2764 KB Output is correct
23 Correct 9 ms 2764 KB Output is correct
24 Correct 10 ms 2764 KB Output is correct
25 Correct 10 ms 2788 KB Output is correct
26 Correct 10 ms 2764 KB Output is correct
27 Correct 10 ms 2764 KB Output is correct
28 Correct 10 ms 2764 KB Output is correct
29 Correct 10 ms 2764 KB Output is correct
30 Correct 10 ms 2832 KB Output is correct
31 Correct 11 ms 2776 KB Output is correct
32 Correct 9 ms 2764 KB Output is correct
33 Correct 8 ms 2760 KB Output is correct
34 Correct 9 ms 2828 KB Output is correct
35 Correct 10 ms 2740 KB Output is correct
36 Correct 10 ms 2816 KB Output is correct
37 Correct 10 ms 2804 KB Output is correct
38 Correct 10 ms 2860 KB Output is correct
39 Correct 7 ms 2764 KB Output is correct
40 Correct 5 ms 2764 KB Output is correct
41 Correct 5 ms 2764 KB Output is correct
42 Correct 5 ms 2764 KB Output is correct
43 Correct 5 ms 2764 KB Output is correct
44 Correct 5 ms 2740 KB Output is correct
45 Correct 5 ms 2764 KB Output is correct
46 Correct 5 ms 2764 KB Output is correct
47 Correct 5 ms 2764 KB Output is correct
48 Correct 5 ms 2764 KB Output is correct
49 Correct 5 ms 2764 KB Output is correct
50 Execution timed out 1097 ms 64200 KB Time limit exceeded
51 Halted 0 ms 0 KB -