QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#203544 | #2476. Pizzo Collectors | whsyhyyh | WA | 1ms | 4396kb | C++14 | 2.1kb | 2023-10-06 18:00:14 | 2023-10-06 18:00:14 |
Judging History
answer
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define N 100010
#define LL long long
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define drep(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
int rd() {
int res=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f*=-1;ch=getchar();}
while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
return res*f;
}
int n,K,p;
char s[N],ch;
int val[30];
int vis[N],vis2[N];
LL cs[N];
char ss[N];
LL gets(int c) {
LL res=0;
for(int x=1;x<=n;x*=p) {
rep(i,1,x) {
bool f=1;
for(int j=i;j<=n;j+=x) {
if(s[j]!=(char)(c+'A'-1)) {
f=0;
break;
}
}
if(f) res+=1ll*n/x*val[c];
}
}
return res;
}
int main() {
// freopen("C.in","r",stdin);
n=rd();
scanf("%s",s+1);
for(int i=1;i<=n;i++) ss[i]=s[i];
K=rd();
rep(i,1,K) ch=getchar(),val[ch-'A'+1]=rd();
int mx=0;char mc='#';
rep(i,1,26) if(val[i]>mx) mx=val[i],mc=i+'A'-1;
if(n==1) {
if(s[1]!='?') printf("%d",val[s[1]-'A'+1]);
else {
printf("%d",mx);
}
return 0;
}
LL ans=0;
p=2;
while(n%p) p++;
int m=n,cnt=0;while(m%p==0) m/=p,cnt+=1;
for(int i=cnt;i>=0;i--){
memset(vis,0,sizeof(vis));
memset(vis2,0,sizeof(vis2));
for(int j=1;j<=n;j++){
if(vis[j]) continue;
int t=j,flag=1;char c='#';
LL sb=0,nt=0;
while(1){
t=(t+m-1)%n+1;
if(vis[t]) break;
if(s[t]>='A'&&s[t]<='Z'){
if(c=='#') c=s[t];
else if(c!=s[t]) flag=0;
}
sb+=cs[t];
nt++;
vis[t]=1;
}
if(flag){
LL ah=0;
if(c=='#') nt*=(LL)mx,ah=mx;
else nt*=val[c-'A'+1],ah=val[c-'A'+1];
if(nt>sb){
t=j;
while(1){
t=(t+m-1)%n+1;
if(vis2[t]) break;
cs[t]=ah;
ss[t]=(c=='#')?mc:c;
vis2[t]=1;
}
}
}
}
ans=0;
for(int j=1;j<=n;j++) ans+=cs[j];
m/=p;
}
ans=0;
rep(i,1,26) ans+=gets(i);
printf("%lld",ans);
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 4396kb
input:
8 ?A?B?A?C 3 A 1 B 1000 C 100000
output:
101004
result:
wrong answer 1st lines differ - expected: '1301004', found: '101004'