QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#854080#9916. Defeat the EnemieszenglxWA 2ms11680kbC++202.0kb2025-01-11 21:22:032025-01-11 21:22:04

Judging History

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

  • [2025-01-11 21:22:04]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11680kb
  • [2025-01-11 21:22:03]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
// #define i128 __int128
using namespace std;
typedef long long ll;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int N = 5e5 + 5;
const int mod = 998244353;

int n,m,k;
int a[N];
int b[N];
int c[N];
int A[N];
int lim[N];

int t;

void solve(){
    cin>>n>>m;
    // cout<<(++t)<<endl;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        cin>>b[i];
    cin>>k;
    for(int i=1;i<=k;i++)
        cin>>c[i];
    int mx=0;
    for(int i=1;i<=n;i++)
        mx=max(mx,a[i]+b[i]);
    for(int i=1;i<=m;i++){
        A[a[i]]=0;
    }
    for(int i=1;i<=n;i++){
        A[a[i]]=max(A[a[i]],b[i]);
    }
    int ans1=INF,ans2=0;
    for(int tot=mx;tot<=mx+2*k;tot++){
        for(int i=0;i<=tot;i++){
            lim[i]=k;
        }
        for(int i=1;i<=m;i++){
            if(A[i]&&i+A[i]+k>tot){
                int sum=tot-i-A[i];
                for(int j=max(0LL,A[i]-k+1);j<A[i];j++){
                    lim[j]=min(lim[j],A[i]-j+sum);
                }
            }
        }
        vector<int> f(mx+2*k+1,1e18),g(mx+2*k+1,0);
        
        f[0]=0;g[0]=1;
        for(int i=0;i<=tot;i++){
            for(int j=1;j<=lim[i];j++){
                if(i+j<=tot){
                    int tmp=f[i]+c[j];
                    if(tmp<f[i+j]){
                        f[i+j]=tmp;
                        g[i+j]=g[i];
                    }else if(tmp==f[i+j]){
                        g[i+j]=(g[i+j]+g[i])%mod;
                    }
                }
            }
        }
        // cout<<f[tot]<<' '<<g[tot]<<endl;
        if(ans1>f[tot]){
            ans1=f[tot];
            ans2=g[tot];
        }else if(ans1==f[tot]){
            ans2=(ans2+g[tot])%mod;
        }
    }
    cout<<ans1<<' '<<ans2<<endl;
    return;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout<<setiosflags(ios::fixed)<<setprecision(1);
    int T=1;cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11664kb

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 4
18 18
99 44387

result:

ok 8 numbers

Test #2:

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

input:

1000
5 3
1 1 3 1 2
3 2 1 1 2
1
5
5 3
3 3 2 2 1
1 1 3 1 1
3
3 1 3
5 5
4 3 5 1 4
5 5 2 5 5
2
1 5
5 5
5 5 5 5 4
2 1 2 4 1
2
1 1
5 3
2 1 2 1 1
1 3 2 1 1
1
5
2 1
1 1
1 1
3
2 2 1
5 5
2 3 5 2 2
5 2 4 3 1
2
3 3
5 1
1 1 1 1 1
1 1 1 1 1
3
5 4 4
5 4
1 4 4 4 2
4 3 1 3 3
1
2
1 5
2
2
3
4 2 4
1 5
4
5
1
4
2 5
1 5
1...

output:

20 1
3 1
9 1
5 4
20 1
2 1
15 4
8 4
14 1
10 3
36 1
12 1
27 1
2 1
20 1
4 1
10 1
23 1
10 1
4 1
28 1
4 1
5 1
4 1
6 1
8 1
6 1
16 1
9 6
5 1
30 1
4 1
6 2
6 1
35 1
10 1
2 1
4 1
15 6
4 1
20 1
4 1
6 1
40 1
6 1
18 1
8 1
10 2
6 1
3 1
10 1
4 2
9 1
8 1
4 1
6 4
20 1
8 2
10 1
2 1
2 1
50 1
24 1
6 1
10 16
10 1
9 1
4 ...

result:

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