結果

問題 No.2659 Manga App
ユーザー lgswdnlgswdn
提出日時 2024-03-09 08:47:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,983 bytes
コンパイル時間 2,557 ms
コンパイル使用メモリ 204,100 KB
実行使用メモリ 128,768 KB
最終ジャッジ日時 2024-03-09 08:47:26
合計ジャッジ時間 8,317 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
67,148 KB
testcase_01 AC 18 ms
67,148 KB
testcase_02 AC 17 ms
67,148 KB
testcase_03 AC 17 ms
67,148 KB
testcase_04 AC 17 ms
67,148 KB
testcase_05 AC 18 ms
67,148 KB
testcase_06 AC 17 ms
67,148 KB
testcase_07 AC 17 ms
67,148 KB
testcase_08 AC 18 ms
67,148 KB
testcase_09 AC 17 ms
67,148 KB
testcase_10 AC 197 ms
128,768 KB
testcase_11 AC 17 ms
67,148 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 20 ms
71,348 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 77 ms
112,336 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 169 ms
128,768 KB
testcase_33 AC 169 ms
128,768 KB
testcase_34 AC 98 ms
116,476 KB
testcase_35 AC 130 ms
128,768 KB
testcase_36 AC 164 ms
128,768 KB
testcase_37 AC 129 ms
128,768 KB
testcase_38 AC 129 ms
128,768 KB
testcase_39 AC 133 ms
128,768 KB
testcase_40 AC 137 ms
128,768 KB
testcase_41 AC 143 ms
128,768 KB
testcase_42 AC 149 ms
128,768 KB
testcase_43 AC 156 ms
128,768 KB
testcase_44 AC 162 ms
128,768 KB
testcase_45 AC 162 ms
128,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//Shirasu Azusa 2024.03
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} 
  return x*w;
}

const int N=2005,inf=0x3f3f3f3f3f3f3f3f;
int n,x,y,m,d,f[N][2*N],g[N][2*N],ans=inf,a[N],b[N],s[N];

int calc(int t) {
  return max(0ll,t%d-x);
}

signed main() {
  n=read()-1, x=read(), y=read(), m=read(), d=x+y;
  rep(i,1,n) a[i]=read();
  per(i,n,1) s[i]=s[i+1]+a[i];
  memset(f,0x3f,sizeof(f)); f[0][0]=0;
  int zz=0;
  rep(i,1,n) {
    int p0=i, p1=i+1, q0=0, q1=a[i]+x;
    while(p0<=n&&!calc(q0)) q0+=a[p0], p0++; p0--;
    while(p1<=n&&!calc(q1)) q1+=a[p1], p1++; p1--;
    //cout<<i<<" "<<p0<<" "<<q0<<" "<<p1<<" "<<q1<<endl;
    rep(j,0,2*(i-1)) {
      if(!(j&1)) {
        if(q0%d>x) {
          if(chmin(f[p0][j+2],f[i-1][j])) g[p0][j+2]=g[i-1][j]+q0/d;
          if(chmin(f[p0][j+1],f[i-1][j]+q0%d-x)) g[p0][j+1]=g[i-1][j]+q0/d;
        }
      } else {
        if(q1%d>x) {
          if(chmin(f[p1][j+1],f[i-1][j])) g[p1][j+1]=g[i-1][j]+q1/d;
          if(chmin(f[p1][j],f[i-1][j]+q1%d-x)) g[p1][j]=g[i-1][j]+q1/d;
        }
      }
    }
  }
  //cout<<ans<<endl;
  rep(i,0,n) {
    int H=0, W=0, Hx=x, Wx=0;
    rep(j,i+1,n) {
      H+=a[j]; int z=calc(H);
      if(z) H-=z, W+=z;
      Hx+=a[j]; z=calc(Hx);
      //cout<<"  "<<j<<" "<<a[j]<<" "<<Hx<<" "<<z<<endl;
      if(z) Hx-=z, Wx+=z;
    }
    //cout<<H<<" "<<W<<endl;
    if(W<=m) {
      int j=0;
      rep(j,0,2*i) {
        int l=j/2*d+g[i][j]*d, r, rem;
        if(j%2==0) rem=m-W; else rem=m-Wx;
        if(f[i][j]>rem) continue;
        if(j%2==0) r=H-min(s[i+1]-W,rem-f[i][j]);
        else r=Hx-min(s[i+1]-Wx,rem-f[i][j]);
        //cout<<i<<" "<<j<<" "<<f[i][j]<<" "<<l<<" "<<r<<endl;
        int res=l+r, z=calc(res); if(z) res+=y-z;
        chmin(ans,res);
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}
0