結果

問題 No.2659 Manga App
ユーザー lgswdnlgswdn
提出日時 2024-03-09 08:47:18
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,983 bytes
コンパイル時間 2,420 ms
コンパイル使用メモリ 203,408 KB
実行使用メモリ 127,332 KB
最終ジャッジ日時 2024-09-29 21:11:27
合計ジャッジ時間 7,617 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28 WA * 18
権限があれば一括ダウンロードができます

ソースコード

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