QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203439 | #2476. Pizzo Collectors | whsyhyyh# | WA | 0ms | 3972kb | C++14 | 1.4kb | 2023-10-06 17:27:41 | 2023-10-06 17:27:41 |
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() {
// freopen("C.in","r",stdin);
n=rd();
scanf("%s",s+1);
K=rd();
rep(i,1,K) ch=getchar(),val[ch-'A'+1]=rd();
if(n==1) {
if(s[1]!='?') printf("%d",val[s[1]-'A'+1]);
else {
int mx=0;
rep(i,1,26) mx=max(mx,val[i]);
printf("%d",mx);
}
return 0;
}
p=2;
while(n%p) p++;
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: 3916kb
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: 0ms
memory: 3848kb
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: 3916kb
input:
2 AB 2 A 1 B 2
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
7 ??????? 3 A 1 B 3 C 2
output:
42
result:
ok single line: '42'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3844kb
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
output:
26
result:
ok single line: '26'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
4 A?A? 2 A 10 B 25
output:
140
result:
ok single line: '140'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3912kb
input:
1 ? 26 A 925691 B 784415 C 459872 D 532761 E 723841 F 43610 G 550337 H 362598 I 433441 J 830094 K 706780 L 870926 M 169396 N 614810 O 151788 P 802159 Q 74805 R 357984 S 654014 T 738826 U 367213 V 361083 W 22154 X 662187 Y 120341 Z 932546
output:
932546
result:
ok single line: '932546'
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3972kb
input:
8 AB??BBBC 3 A 226880 B 21007 C 187937
output:
1292607
result:
wrong answer 1st lines differ - expected: '1331550', found: '1292607'