QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#854043 | #9916. Defeat the Enemies | zenglx | WA | 0ms | 11992kb | C++20 | 2.0kb | 2025-01-11 21:09:07 | 2025-01-11 21:09:08 |
Judging History
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<=2*m;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: 0
Wrong Answer
time: 0ms
memory: 11992kb
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:
1 9 1 2 6 4 3 18 18 4 99 44387
result:
wrong answer 1st numbers differ - expected: '9', found: '1'