QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203428 | #2476. Pizzo Collectors | Vengeful_Spirit# | WA | 0ms | 3976kb | C++14 | 1.6kb | 2023-10-06 17:24:20 | 2023-10-06 17:24:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int p;
const int N=100001;
const int INF=1e9;
int f[N][18][27];
int val[26];
char s[N],t[N],bs[N];
int n,m;
void dfs(int i,int len,int j){
if(len==1){
if(s[i]=='?'){
for(int c=0;c<26;c++)f[i][j][c]=val[c];
}
else{
for(int c=0;c<26;c++)f[i][j][c]=-INF;
f[i][j][s[i]-'A']=val[s[i]-'A'];
}
}
else{
for(int k=0;k<p;k++){
dfs(i+k*(bs[j]),len/p,j+1);
}
for(int k=0;k<p;k++){
f[i][j][26]+=f[i+k*bs[j]][j+1][26];
}
for(int c=0;c<26;c++){
for(int k=0;k<p;k++){
if(f[i+k*bs[j]][j+1][c]<=-INF){f[i][j][c]=-INF;break;}
f[i][j][c]+=f[i+k*bs[j]][j+1][c];
// cout<<"c: "<<c<<" "<<i+k*(len/p)<<" "<<j+1<<" "<<f[i][j][c]<<endl;
}
// cout<<"c: "<<c<<" "<<f[i][j][c]<<endl;
f[i][j][c]+=len*val[c];
// cout<<"c: "<<c<<" "<<f[i][j][c]<<endl;
f[i][j][26]=max(f[i][j][26],f[i][j][c]);
}
}
}
signed main(){
scanf("%lld",&n);
scanf("%s",s+1);
scanf("%lld",&m);
for(int i=1;i<=m;i++){
int x;
scanf("%s%lld",t,&x);
val[t[0]-'A']=x;
}
for(int i=2;i<=n;i++){
if(n%i==0){
p=n;
while(p!=1)p/=i;
p=i;break;
}
}
bs[0]=1;
for(int i=1;i<=20;i++){
bs[i]=bs[i-1]*p;
}
dfs(1,n,0);
printf("%lld\n",f[1][0][26]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3976kb
input:
8 ?A?B?A?C 3 A 1 B 1000 C 100000
output:
1200004
result:
wrong answer 1st lines differ - expected: '1301004', found: '1200004'