結果

問題 No.409 ダイエット
ユーザー rapurasurapurasu
提出日時 2017-06-15 13:23:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 2,103 bytes
コンパイル時間 1,474 ms
コンパイル使用メモリ 165,628 KB
実行使用メモリ 10,092 KB
最終ジャッジ日時 2023-09-08 17:30:34
合計ジャッジ時間 6,918 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,444 KB
testcase_01 AC 3 ms
7,424 KB
testcase_02 AC 3 ms
7,432 KB
testcase_03 AC 2 ms
7,428 KB
testcase_04 AC 3 ms
7,420 KB
testcase_05 AC 3 ms
7,440 KB
testcase_06 AC 3 ms
7,436 KB
testcase_07 AC 3 ms
7,424 KB
testcase_08 AC 3 ms
7,540 KB
testcase_09 AC 3 ms
7,424 KB
testcase_10 AC 2 ms
7,484 KB
testcase_11 AC 3 ms
7,512 KB
testcase_12 AC 3 ms
7,428 KB
testcase_13 AC 3 ms
7,484 KB
testcase_14 AC 2 ms
7,440 KB
testcase_15 AC 3 ms
7,432 KB
testcase_16 AC 3 ms
7,440 KB
testcase_17 AC 2 ms
7,476 KB
testcase_18 AC 3 ms
7,556 KB
testcase_19 AC 3 ms
7,496 KB
testcase_20 AC 3 ms
7,488 KB
testcase_21 AC 3 ms
7,420 KB
testcase_22 AC 3 ms
7,432 KB
testcase_23 AC 3 ms
7,540 KB
testcase_24 AC 3 ms
7,432 KB
testcase_25 AC 3 ms
7,432 KB
testcase_26 AC 3 ms
7,472 KB
testcase_27 AC 2 ms
7,472 KB
testcase_28 AC 3 ms
7,436 KB
testcase_29 AC 3 ms
7,504 KB
testcase_30 AC 3 ms
7,516 KB
testcase_31 AC 3 ms
7,428 KB
testcase_32 AC 3 ms
7,420 KB
testcase_33 AC 2 ms
7,424 KB
testcase_34 AC 3 ms
7,484 KB
testcase_35 AC 4 ms
7,456 KB
testcase_36 AC 4 ms
7,456 KB
testcase_37 AC 3 ms
7,752 KB
testcase_38 AC 4 ms
7,460 KB
testcase_39 AC 4 ms
7,588 KB
testcase_40 AC 4 ms
7,660 KB
testcase_41 AC 4 ms
7,460 KB
testcase_42 AC 4 ms
7,448 KB
testcase_43 AC 4 ms
7,440 KB
testcase_44 AC 4 ms
7,432 KB
testcase_45 AC 3 ms
7,448 KB
testcase_46 AC 4 ms
7,496 KB
testcase_47 AC 4 ms
7,504 KB
testcase_48 AC 3 ms
7,428 KB
testcase_49 AC 3 ms
7,456 KB
testcase_50 AC 4 ms
7,488 KB
testcase_51 AC 3 ms
7,440 KB
testcase_52 AC 4 ms
7,460 KB
testcase_53 AC 4 ms
7,452 KB
testcase_54 AC 4 ms
7,452 KB
testcase_55 AC 29 ms
8,448 KB
testcase_56 AC 55 ms
8,248 KB
testcase_57 AC 58 ms
10,092 KB
testcase_58 AC 27 ms
8,344 KB
testcase_59 AC 40 ms
8,544 KB
testcase_60 AC 25 ms
8,216 KB
testcase_61 AC 51 ms
9,516 KB
testcase_62 AC 52 ms
9,896 KB
testcase_63 AC 55 ms
9,464 KB
testcase_64 AC 30 ms
8,332 KB
testcase_65 AC 62 ms
9,128 KB
testcase_66 AC 58 ms
9,748 KB
testcase_67 AC 46 ms
9,192 KB
testcase_68 AC 42 ms
8,632 KB
testcase_69 AC 55 ms
9,456 KB
testcase_70 AC 78 ms
9,436 KB
testcase_71 AC 43 ms
8,652 KB
testcase_72 AC 94 ms
9,852 KB
testcase_73 AC 91 ms
9,404 KB
testcase_74 AC 51 ms
8,704 KB
testcase_75 AC 87 ms
9,400 KB
testcase_76 AC 60 ms
9,200 KB
testcase_77 AC 46 ms
8,276 KB
testcase_78 AC 46 ms
8,976 KB
testcase_79 AC 39 ms
8,344 KB
testcase_80 AC 85 ms
9,856 KB
testcase_81 AC 90 ms
9,376 KB
testcase_82 AC 64 ms
9,020 KB
testcase_83 AC 69 ms
9,072 KB
testcase_84 AC 60 ms
8,464 KB
testcase_85 AC 9 ms
7,528 KB
testcase_86 AC 59 ms
8,612 KB
testcase_87 AC 76 ms
9,380 KB
testcase_88 AC 34 ms
7,972 KB
testcase_89 AC 71 ms
8,328 KB
testcase_90 AC 34 ms
7,676 KB
testcase_91 AC 75 ms
8,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

 #include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
int N,A,B,W;
int D[300011];
int sum[300011];
LL que[300011];
LL day[300011];

void calc_sum(){
     sum[0]=0;
     REP(i,300010){
        sum[i+1]=sum[i]-A+B*(i+1);
     }
}

LL change(LL q1,LL d1,LL q2,LL d2){
   q1+=sum[(d2-d1)];
   if(q2<=q1)return 0;
   if(B==0)return 1e9;
   LL btk=q2-q1;
   
   return btk/(B*(d2-d1))+1+d2;
}

int main(){
    cin>>N>>A>>B>>W;
    calc_sum();
    REP(i,N){
       cin>>D[i+1];
    }
   /* REP(i,N+1){
        printf("sum[%d]=%d",i,sum[i]);
    }*/
    que[0]=0;
    day[0]=0;
    int l=0,r=1;
    REP(i,N+1){
        if(i==0)continue;
        int n_day=i;
        //先頭の更新
        while(1){
           if(r-l==1)break;//queに要素が1つ
           if(change(que[l],day[l],que[l+1],day[l+1])<n_day){
              //printf("change%d\n",change(que[l],day[l],que[l+1],day[l+1]));
             // printf("l,que=%d,day=%d,\n",que[l],day[l]);
              l++;

           }else{
             // printf("change%d\n",change(que[l],day[l],que[l+1],day[l+1]));
              //printf("l,day=%dday2=%d,\n",day[l],day[l+1]);
              break;
           }
        }
        //後ろに追加
        que[r]=que[l]+sum[n_day-day[l]-1]+D[n_day];//これを後ろに追加
        day[r]=n_day;
       // cout<<"ok"<<endl;
        //後ろの更新
        while(1){
            if(r-l==0)break;
            if(r-l==1)break;
            if(change(que[r-1],day[r-1],que[r],day[r])<change(que[r-2],day[r-2],que[r-1],day[r-1])){
               //printf("r,que=%d,day=%d\n",que[r-1],day[r-1]);
               que[r-1]=que[r];
               day[r-1]=day[r];
               r--;
            }else{
               break;
            }
        }
        r++;
    }
    //残ったもので計算
    LL ans=1e17;
    //printf("l=%d,r=%d\n",l,r);
    for(int i=l;i<r;i++){
        //cout<<que[i]<<" "<<day[i]<<endl;
        ans=min(ans,que[i]+sum[N-day[i]]);
    }
    //cout<<ans<<endl;
    cout<<ans+W<<endl;
    return 0;
}
0