QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#858445#9916. Defeat the EnemiesItgsurf#WA 1ms10064kbC++141.4kb2025-01-16 17:22:492025-01-16 17:22:50

Judging History

This is the latest submission verdict.

  • [2025-01-16 17:22:50]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 10064kb
  • [2025-01-16 17:22:49]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

const int mod=998244353;
const LL INF=1e16;
const int N=5e5+5,M=1e4+5,K=105;

int T,n,m,k;
int a[N],b[N],c[K];
LL f[M],cnt[M];
LL ff[M][K],ccnt[M][K];

int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;++i) scanf("%d",a+i);
		for(int i=1;i<=n;++i) scanf("%d",b+i);
		scanf("%d",&k);
		for(int i=1;i<=k;++i) scanf("%d",c+i);
		
		f[0]=0,cnt[0]=1;
		for(int i=1;i<=m;++i){
			f[i]=INF,cnt[i]=0;
			for(int j=1;j<=k&&j<=i;++j){
				if(f[i-j]+c[j]<f[i])
					f[i]=f[i-j]+c[j],
					cnt[i]=cnt[i-j];
				else if(f[i-j]+c[j]==f[i])
					cnt[i]=(cnt[i]+cnt[i-j])%mod;
			}
		}
		
		for(int i=1;i<=m;++i)
			for(int j=1;j<=k;++j){
				ff[i][j]=f[i],ccnt[i][j]=cnt[i];
				for(int x=1;x<j;++x)
					if(f[i+x]<ff[i][j])
						ff[i][j]=f[i+x],
						ccnt[i][j]=cnt[i+x];
					else if(f[i+x]==ff[i][j])
						ccnt[i][j]=(ccnt[i][j]+cnt[i+x])%mod;
			}
			
		LL a1=0,a2=0;
		for(int i=1;i<=n;++i){
			LL c1=INF,c2=0;
			for(int j=1;j<=k;++j)
				for(int x=1;x<=k;++x){
					LL cost=ff[a[i]-j][j]+c[j]+ff[b[i]-x][x]+c[x];
					if(cost<c1) c1=cost,c2=ccnt[a[i]-j][j]*ccnt[b[i]-x][x]%mod;
					else if(cost==c1) c2=(c2+ccnt[a[i]-j][j]*ccnt[b[i]-x][x])%mod;
				}
			if(c1>a1)
				a1=c1,
				a2=c2%mod;
			else if(c1==a1)
				a2=(a2+c2)%mod;
		}
		printf("%lld %lld\n",a1,a2);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 10064kb

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 0
6 0
17 30
96 89124

result:

wrong answer 2nd numbers differ - expected: '1', found: '0'