QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#354629#8276. Code Congestionmc020207#WA 3ms8356kbC++171.8kb2024-03-15 19:19:422024-03-15 19:19:44

Judging History

你现在查看的是最新测评结果

  • [2024-03-15 19:19:44]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:8356kb
  • [2024-03-15 19:19:42]
  • 提交

answer

#include<bits/stdc++.h>
#define MAXN 210
#define MOD 998244353
#define LL long long
using namespace std;
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rof(i,a,b) for(int i=(a);i>=(b);i--)
LL a[MAXN],t[MAXN],sa[MAXN],st[MAXN];
LL dp[300010],num[300010],dp2[300010],num2[300010];
int n,T;
LL mi(LL x,LL y){
    LL ans=1;
    while (y){
        if (y&1) ans=1LL*ans*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return ans;
}
int main(){
    std::ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>T;
    For(i,1,n) {cin>>a[i];sa[i]=sa[i-1]+a[i];}
    For(i,1,n) {cin>>t[i];st[i]=st[i-1]+t[i];}
    if (st[n]<=T){
        cout<<mi(2,n)*sa[n]%MOD;
        return 0;
    }
    LL ans=0;
    num[0]=1;
    Rof(i,n,1){
        if (st[i-1]<=T){
            LL now=0;
            For(j,T-st[i]+1,T-st[i-1]){
                if (j<0) continue;
                now=(now+dp[j])%MOD;
            }
            ans=(ans+(now+sa[i-1])*(mi(2,i-1)+MOD-1))%MOD;
            // printf("i=%d ans=%d\n",i,ans);
        }
        Rof(j,T,0){
            if (j-t[i]<0) break;
            dp[j]=(dp[j]+dp[j-t[i]]+a[i]*num[j-t[i]])%MOD;
            num[j]=(num[j]+num[j-t[i]])%MOD;
        }
        // printf("i=%d\n",i);
        // For(j,0,T) printf("dp[%d]=%d num[%d]=%d\n",j,dp[j],j,num[j]);
    }
    memset(dp,0,sizeof(dp));
    memset(num,0,sizeof(num));
    num[0]=1;
    For(i,1,n){
        For(j,T-t[i]+1,T){
            if (j<0) continue;
            ans=(ans+dp[j]*mi(2,n-i))%MOD;
        }
        if (T-t[i]>=0) ans=(ans+dp[T-t[i]]+a[i]*num[T-t[i]])%MOD;
        // printf("i=%d ans=%d\n",i,ans);
        Rof(j,T,0){
            if (j-t[i]<0) break;
            dp[j]=(dp[j]+dp[j-t[i]]+a[i]*num[j-t[i]])%MOD;
            num[j]=(num[j]+num[j-t[i]])%MOD;
        }
    }
    cout<<ans;
}
/*
3 3
2 3 4
1 2 2
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 8356kb

input:

3 3
2 3 4
1 2 2

output:

40

result:

ok 1 number(s): "40"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 8300kb

input:

13 96
56231 258305 150103 164646 232643 37457 239584 192517 167805 215281 159832 98020 141006
54 1 38 1 4 1 4 11 1 4 8 22 1

output:

354695674

result:

wrong answer 1st numbers differ - expected: '745634757', found: '354695674'