답안 #1099436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099436 2024-10-11T09:58:30 Z alexander707070 Tortoise (CEOI21_tortoise) C++14
0 / 100
0 ms 344 KB
#include<bits/stdc++.h>
#define MAXN 307
using namespace std;

int n,a[MAXN];
int dist[MAXN],last,sum,nxt[MAXN];

int dp[MAXN][2*MAXN][2];
bool li[MAXN][2*MAXN][2];

int suff[MAXN][3*MAXN];

int ff(int pos,int tim,int c){
    if(tim>2*n or pos>n)return 0;
    return dp[pos][tim][c];
}

struct Fenwick{
    int fenwick[MAXN];

    void update(int x,int val){
        while(x<=n){
            fenwick[x]=max(fenwick[x],val);
            x+=(x & (-x));
        }
    }

    int getmax(int x){
        int res=0;
        while(x>=1){
            res=max(res,fenwick[x]);
            x-=(x & (-x));
        }
        return res;
    }
};

Fenwick fen[3*MAXN];

void calcdp(){
    for(int pos=n;pos>=1;pos--){
        for(int tim=2*n;tim>=0;tim--){
            for(int c=1;c>=0;c--){
                
                if(c==1){
                    if(nxt[pos]==2*n)dp[pos][tim][c]=0;
                    else{
                        if(tim+2*nxt[pos]-pos>3*n)dp[pos][tim][c]=1;
                        else dp[pos][tim][c]=fen[tim+2*nxt[pos]-pos].getmax(nxt[pos])+1;
                    }
                }else{
                    if(a[pos]>0){
                        if(tim<=2*(pos-1))dp[pos][tim][c]=max(dp[pos][tim][c],ff(pos,tim,1));

                        for(int s=0;tim+s*2*dist[pos]<=2*(pos-1) and s+1<=a[pos];s++){
                            dp[pos][tim][c]=max(dp[pos][tim][c],ff(pos+1,tim+(s+1)*2*dist[pos]+1,0)+s+1);

                            if(s+1<a[pos] and tim+2*(s+1)*dist[pos]<=2*(pos-1))dp[pos][tim][c]=max(dp[pos][tim][c], ff(pos,tim+(s+1)*2*dist[pos],1)+s+1);
                        }
                    }

                    if(pos<n)dp[pos][tim][c]=max(dp[pos][tim][c],ff(pos+1,tim+1,c));

                    fen[pos+tim].update(pos,dp[pos][tim][c]);
                }
            }
        }
    }
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        dist[i]=n;

        if(a[i]>=0)sum+=a[i];
    }

    last=-n;
    for(int i=1;i<=n;i++){
        if(a[i]==-1)last=i;
        dist[i]=min(dist[i],i-last);
    }

    last=2*n;
    for(int i=n;i>=1;i--){
        if(a[i]==-1)last=i;
        dist[i]=min(dist[i],last-i);
        
        nxt[i]=last;
    }

    calcdp();
    cout<<sum-dp[1][0][0]<<"\n";
 
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -