QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#431397 | #6849. Mr. Liang play Card Game | Cidoai | WA | 11ms | 9036kb | C++14 | 1.6kb | 2024-06-05 14:21:06 | 2024-06-05 14:21:07 |
Judging History
answer
#include<cstdio>
typedef long long ll;
inline ll read(){
ll x=0;
int f=0,ch=0;
while(ch<48||ch>57) f=(ch=='-'),ch=getchar();
while(ch>47&&ch<58) x=(x<<3)+(x<<1)+(ch&15),ch=getchar();
return f?-x:x;
}
inline void write(ll x,char end=' '){
if(x==0){
putchar('0');
putchar(end);
return;
}
if(x<0) putchar('-'),x=-x;
int ch[40]={0},cnt=0;
while(x){
ch[cnt++]=(int)(x%10);
x/=10;
}
while(cnt--) putchar(ch[cnt]+48);
putchar(end);
}
inline ll max(ll x,ll y){return x>y?x:y;}
int a[105];
ll v[105];
int n,m,r;
ll p;
ll dp[105][105];
ll f[105][105][105];
int cnt[105];
int main(){
int T=read();
while(T--){
n=read(),m=read(),r=read(),p=read();
for(int i=1;i<=m;++i) cnt[i]=0;
for(int i=1;i<=n;++i) a[i]=read(),cnt[a[i]]++;
for(int i=1;i<=m;++i) v[i]=read();
for(int l=n;l>=1;--l){
for(int r=l;r<=n;++r){
dp[l][r]=-1e18;
for(int k=0;k<=cnt[a[r]];++k)
f[l][r][k]=-1e18;
if(l==r){
dp[l][r]=v[a[l]];
f[l][r][1]=0;
continue;
}
f[l][r][1]=0;
for(int p=l;p<r;++p){
if(a[p]==a[r]){
for(int i=1;i<cnt[a[r]];++i){
ll x=f[l][r][i+1];
ll y=f[l][p][i]+dp[p+1][r-1];
f[l][r][i+1]=max(x,y);
}
}
}
for(int k=l;k<r;++k)
dp[l][r]=max(dp[l][r],dp[l][k]+dp[k+1][r]);
for(int k=l;k<=r;++k){
ll c=v[a[k]];
for(int lg=0;lg<=r-1&&(1<<lg)<=cnt[a[k]];++lg){
int d=1<<lg;
dp[l][r]=max(dp[l][r],f[l][k][d]+c+dp[k+1][r]);
c*=p;
}
}
}
}
write(dp[1][n],'\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 11ms
memory: 9036kb
input:
50 55 2 3 8 2 1 2 1 2 2 2 1 1 1 2 2 1 1 2 1 1 2 2 1 1 1 1 1 2 2 1 1 2 2 2 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 2 1 2 2 2 1 1 1 42126 55001 55 3 1 8 2 3 1 1 3 3 3 2 1 2 1 2 1 2 1 3 1 3 3 2 3 2 2 3 1 1 2 2 2 2 2 3 3 2 2 2 3 1 3 2 1 2 2 1 1 2 2 3 3 3 1 1 3 3 2 39105 57552 26545 55 2 3 9 2 1 2 2 2 2 2 2 2 2 ...
output:
406175740 260241273 5454831537 3661875 145721376 2189194 334792 859244 1057821 276184 2317173 3913959 1475228 14749831 9380633 331782 948220 952455 977955 1210135 103980 1553308 311282 1740740 773077 1426404 11225924 1239955 38009547 120368 168264 11240455 1259948 680475 528194 986700 2742096 173994...
result:
wrong answer 1st lines differ - expected: '38200162', found: '406175740'