답안 #417370

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417370 2021-06-03T15:39:15 Z doowey Cigle (COI21_cigle) C++14
0 / 100
6 ms 588 KB
#include <bits/stdc++.h>

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 5010;
int dp[N][N];
int D[N];

struct Node{
    int val;
    int lzy;
};

Node T[N * 4 + 16];

void push(int node, int cl, int cr){
    T[node].val += T[node].lzy;
    if(cl != cr){
        T[node * 2].lzy += T[node].lzy;
        T[node * 2 + 1].lzy += T[node].lzy;
    }
    T[node].lzy = 0;
}

void update(int node, int cl, int cr, int tl, int tr, int v){
    push(node, cl, cr);
    if(cl >= tl && cr <= tr){
        T[node].lzy = v;
        push(node, cl, cr);
        return;
    }
    int mid = (cl + cr) / 2;
    if(mid >= tl)
        update(node * 2, cl, mid, tl, tr, v);
    else{
        push(node * 2, cl, mid);
    }
    if(mid + 1 <= tr)
        update(node * 2 + 1, mid + 1, cr, tl, tr, v);
    else
        push(node * 2 + 1, mid + 1, cr);
    T[node].val = max(T[node * 2].val, T[node * 2 + 1].val);
}

int en;

void build(int node, int cl, int cr, int en){
    T[node].lzy = 0;
    if(cl == cr){
        T[node].val = dp[cl][en - 1];
        return;
    }
    int mid = (cl + cr) / 2;
    build(node * 2, cl, mid, en);
    build(node * 2 + 1, mid + 1, cr, en);
    T[node].val = max(T[node * 2].val, T[node * 2 + 1].val);
}

int main(){
    fastIO;
    //freopen("in.txt","r",stdin);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i ++ ){
        cin >> D[i];
    }
    int pp;
    int cum;
    int cur;
    int outp = 0;
    for(int cut = 2; cut <= n; cut ++ ){
        build(1, 1, cut - 1, cut);
        cur = 0;
        cum = 0;
        pp = cut;
        for(int go = cut; go <= n; go ++ ){
            dp[cut][go] = T[1].val;
            if(go == n)
                outp = max(outp, dp[cut][go]);

            cur += D[go];
            while(pp > 1 && cum < cur){
                pp --;
                cum += D[pp];
            }
            if(cum == cur){
                update(1, 1, cut - 1, 1, pp - 1, +1);
            }
        }
    }
    cout << outp << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 568 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -