QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203294 | #2476. Pizzo Collectors | Delay_for_five_minutes# | WA | 1ms | 5492kb | C++20 | 1.8kb | 2023-10-06 16:38:23 | 2023-10-06 16:38:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
int n;
ll val[26];
string s;
int k,p;
ll f[18][100005];
int fpow(int a,int b)
{
int ans = 1;
while(b--) ans *= a;
return ans;
}
int main()
{
// freopen("in.txt","r",stdin) ;
ios::sync_with_stdio(false) ; cin.tie(0) ;cout.tie(0) ;
cin >> n; cin >> s; cin >> k;
for(int i = 0;i < 26;i++) val[i] = -1e18;
for(int i = 1;i <= k;i++) {
char c;
int d;cin >> c >> d;
val[c - 'A'] = d;
}
for(int i = 2;i <= n;i++) {
int hs = 1,j;
for(j = 0; hs < n;j++) {
hs = hs * i;
}
if(hs == n) {
p = i , k = j ; break ;
}
}
int mx = 0;
for(int i = 0;i < 26;i++) mx = max(1LL*mx , val[i]) ;
for(int i = k;i >= 0;i--) { ///步长为p^i
int d = fpow(p , k - i) ; ///一圈的大小
int step = fpow(p , i) ;
for(int j = 0;j < step;j++) {
int cha = -1;
for(int k = j ; ; k = (k + step) % n) {
if(s[k] != '?') {
if(cha == -1) cha = s[k] - 'A';
else {
if(cha != s[k] - 'A') {cha = -2;break ;}
}
}
if((k + step) % n == j) break ;
}
f[i][j] = -1e18;
if(cha != -2) {
if(cha == -1) f[i][j] = 1LL * mx * d * (k - i+1);
else f[i][j] = 1LL*val[cha] * d * (k - i+1);
}
if(i != k) {
ll f2 = 0;
for(int u = 0;u < p;u++) f2 += f[i + 1][(j + u*step) % (step * p)] ;
f[i][j] = max(f[i][j] , f2) ;
}
// printf("%d %d %lld\n",i,j,f[i][j]) ;
}
}
cout << f[0][0] << '\n' ;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5448kb
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: 5492kb
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: 3576kb
input:
2 AB 2 A 1 B 2
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5488kb
input:
7 ??????? 3 A 1 B 3 C 2
output:
42
result:
ok single line: '42'
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3444kb
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:
0
result:
wrong answer 1st lines differ - expected: '26', found: '0'