QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#838772#9916. Defeat the EnemiesSpicyTomatoWA 0ms16016kbC++144.3kb2024-12-31 21:49:352024-12-31 21:49:37

Judging History

This is the latest submission verdict.

  • [2024-12-31 21:49:37]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 16016kb
  • [2024-12-31 21:49:35]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

int t,bigger[101][2],n,m,k,a[500001],b[500001],ks[101],mod=998244353,cur,temp,ma[5001];
vector<int> mv[5001];  //破盾到第i层时,剩余最大hp的所有可能值
long long dp[5001][5001][2];  //破盾到第i层时,耗费的最小费用和对应的方案数量
long long just[5001][2]={0},hp[5001][2]={0},op1,op2,inf=1e18;

void check()
{
    for(int i=1;i<=k;i+=1) cout<<bigger[i][0]<<" ";
    cout<<endl;
    for(int i=1;i<=k;i+=1) cout<<bigger[i][1]<<" ";
    cout<<endl;
    for(int i=1;i<=m;i+=1) cout<<just[i][0]<<" ";
    cout<<endl;
    for(int i=1;i<=m;i+=1) cout<<just[i][1]<<" ";
    cout<<endl;
    for(int i=1;i<=m;i+=1) cout<<hp[i][0]<<" ";
    cout<<endl;
    for(int i=1;i<=m;i+=1) cout<<hp[i][1]<<" ";
    cout<<endl;
    for(int i=1;i<=m;i+=1) cout<<ma[i]<<" ";
    cout<<endl;
}

void initialize()
{
    for(int i=1;i<=k;i+=1) bigger[i][0]=1e9+1;
    bigger[k][0]=ks[k];
    bigger[k][1]=1;
    for(int i=k-1;i>0;i-=1)
    {
        if(ks[i]<bigger[i+1][0]) {bigger[i][0]=ks[i];bigger[i][1]=1;}
        else if(ks[i]==bigger[i+1][0]) {bigger[i][0]=ks[i];bigger[i][1]=bigger[i+1][1]+1;}
        else {bigger[i][0]=bigger[i+1][0];bigger[i][1]=bigger[i+1][1];}
    }
    for(int i=1;i<=m;i+=1)
    {
        just[i][0]=inf;
        hp[i][0]=inf;
        mv[i].clear();
        for(int j=0;j<=m;j+=1) dp[i][j][0]=inf;
        ma[i]=0;
    }
    just[0][1]=1;
    hp[0][1]=1;
    for(int i=1;i<=m;i+=1)
    {
        for(int j=1;j<=min(i,k);j+=1)
        {
            if(just[i][0]>just[i-j][0]+ks[j]) {just[i][0]=just[i-j][0]+ks[j];just[i][1]=just[i-j][1];}
            else if(just[i][0]==just[i-j][0]+ks[j]) just[i][1]=(just[i][1]+just[i-j][1])%mod;
        }
    }
    for(int i=1;i<=m;i+=1)
    {
        for(int j=1;j<=min(i,k);j+=1)
        {
            if(hp[i][0]>just[i-j][0]+bigger[j][0]) {hp[i][0]=just[i-j][0]+bigger[j][0];hp[i][1]=(just[i-j][1]*bigger[j][1])%mod;}
            else if(hp[i][0]==just[i-j][0]+bigger[j][0]) hp[i][1]=(hp[i][1]+just[i-j][1]*bigger[j][1])%mod;
        }
    }
    for(int i=1;i<=n;i+=1) ma[b[i]]=max(ma[b[i]],a[i]);
    //check();
}

void check2()
{
    for(int i=0;i<=m;i+=1)
    {
        for(int j=0;j<mv[i].size();j+=1) cout<<mv[i][j]<<" ";
        cout<<endl;
    }
    for(int i=1;i<=m;i+=1)
    {
        for(int j=0;j<=m;j+=1) cout<<dp[i][j][0]<<" ";
        cout<<endl;
    }
    for(int i=1;i<=m;i+=1)
    {
        for(int j=0;j<=m;j+=1) cout<<dp[i][j][1]<<" ";
        cout<<endl;
    }
}

void solve()
{
    cin>>n>>m;
    int max_b=0;
    for(int i=1;i<=n;i+=1) cin>>a[i];
    for(int i=1;i<=n;i+=1) {cin>>b[i];max_b=max(max_b,b[i]);}
    cin>>k;
    for(int i=1;i<=k;i+=1) cin>>ks[i];
    initialize();
    for(int i=1;i<max_b;i+=1)
    {
        cur=0;
        for(int j=1;j<=min(i,k);j+=1)
        {
            cur=max(cur,ma[i-j+1]);
            for(int x=0;x<mv[i-j].size();x+=1)
            {
                temp=max(mv[i-j][x]-j,cur);
                if(dp[i][temp][0]==inf) mv[i].push_back(temp);
                if(dp[i][temp][0]>dp[i-j][mv[i-j][x]][0]+ks[j])
                {
                    dp[i][temp][0]=dp[i-j][mv[i-j][x]][0]+ks[j];
                    dp[i][temp][1]=dp[i-j][mv[i-j][x]][1];
                }
                else if(dp[i][temp][0]==dp[i-j][mv[i-j][x]][0]+ks[j]) dp[i][temp][1]=(dp[i][temp][1]+dp[i-j][mv[i-j][x]][1])%mod;
            }
        }
    }
    //if(m<10) check2();
    cur=0;
    op1=inf;
    for(int i=1;i<=min(max_b,k);i+=1)
    {
        cur=max(cur,ma[max_b-i+1]);
        for(int j=0;j<mv[max_b-i].size();j+=1)
        {
            for(int x=i;x<=min(max_b,k);x+=1)
            {
                temp=max(cur,mv[max_b-i][j]-x);
                if(op1>dp[max_b-i][mv[max_b-i][j]][0]+ks[x]+hp[temp][0])
                {
                    op1=dp[max_b-i][mv[max_b-i][j]][0]+ks[x]+hp[temp][0];
                    op2=dp[max_b-i][mv[max_b-i][j]][1]*hp[temp][1]%mod;
                }
                else if(op1==dp[max_b-i][mv[max_b-i][j]][0]+ks[x]+hp[temp][0]) op2=(op2+dp[max_b-i][mv[max_b-i][j]][1]*hp[temp][1])%mod;
            }
        }
    }
    cout<<op1<<" "<<op2<<endl;
}

int main()
{
    mv[0].push_back(0);
    dp[0][0][0]=0;
    dp[0][0][1]=1;
    cin>>t;
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 16016kb

input:

4
5 5
3 5 2 1 2
3 1 3 2 3
3
2 3 4
3 2
2 2 2
2 2 2
3
2 3 3
7 6
5 3 4 6 6 3 4
4 6 4 2 3 5 5
4
2 4 6 7
10 100
38 49 79 66 49 89 21 55 13 23
67 56 26 39 56 16 84 50 92 82
11
6 6 7 8 9 9 9 9 9 9 9

output:

9 1
6 2
18 18
99 44387

result:

wrong answer 4th numbers differ - expected: '4', found: '2'