QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203416#2476. Pizzo CollectorsVengeful_Spirit#WA 1ms3680kbC++141.6kb2023-10-06 17:18:022023-10-06 17:18:03

Judging History

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

  • [2023-10-06 17:18:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3680kb
  • [2023-10-06 17:18:02]
  • 提交

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<m;c++)f[i][j][c]=val[c];
        }
        else{
            for(int c=0;c<m;c++)f[i][j][c]=-INF;
            f[i][j][s[i]-'A']=val[s[i]-'A'];
          //  cout<<"ori "<<i<<" "<<j<<" "<<f[i][j][s[i]-'A']<<endl;
        }
    }
    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][m]+=f[i+k*bs[j]][j+1][m];
        }
        
 //   cout<<"dfs "<<i<<" "<<len<<' '<<j<<endl;
        for(int c=0;c<m;c++){
            for(int k=0;k<p;k++){
                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][m]=max(f[i][j][m],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][m]);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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'