QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203396 | #2476. Pizzo Collectors | whsyhyyh# | TL | 1ms | 3688kb | C++14 | 1.2kb | 2023-10-06 17:11:44 | 2023-10-06 17:11:44 |
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];
LL pre[30];
LL gets(int c,int flag) {
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)&&(!flag||(flag&&s[j]!='?'))) {
f=0;
break;
}
}
if(f) res+=1ll*n/x*val[c];
}
}
return res;
}
int main() {
n=rd();
p=2;
while(n%p) p++;
scanf("%s",s+1);
K=rd();
rep(i,1,K) ch=getchar(),val[ch-'A'+1]=rd();
rep(i,1,26) pre[i]=gets(i,0);
LL ans=0;
rep(i,1,26) {
LL res=0;
rep(j,1,26) if(j!=i) res+=pre[j];
res+=gets(i,1);
ans=max(ans,res);
}
printf("%lld",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3688kb
input:
8 ?A?B?A?C 3 A 1 B 1000 C 100000
output:
1301004
result:
ok single line: '1301004'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
4 ABCD 4 A 4 B 3 C 2 D 1
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
2 AB 2 A 1 B 2
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
7 ??????? 3 A 1 B 3 C 2
output:
42
result:
ok single line: '42'
Test #5:
score: -100
Time Limit Exceeded
input:
1 ? 26 A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P 16 Q 17 R 18 S 19 T 20 U 21 V 22 W 23 X 24 Y 25 Z 26