QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203181 | #2476. Pizzo Collectors | Team_name# | TL | 1ms | 3436kb | C++20 | 1.5kb | 2023-10-06 15:59:55 | 2023-10-06 15:59:56 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
#define DEBUG_VAR(x) { cerr << "* "x" = " << x << endl; }
#define DEBUG_FMT(...) { cerr << "* "; fprintf(stderr, __VA_ARGS__); }
using namespace std;
using LL = long long;
int n;
int p, m; // n = p^m
string str;
int all;
LL v[26];
LL maxv;
LL solve(int pos, int t)
{
if(t == m) {
if(str[pos] == '?') return maxv;
else return v[str[pos]-'A'];
}
int step = 1;
for(int i = 1; i <= t; i++)
step *= p;
bool flag = true;
char curC = 'A'-1;
bool hasTwoC = false;
for(int i = pos; i != pos || flag; i = (i+step)%n) {
flag = false;
if(str[i] == '?') continue;
else {
if(curC == 'A'-1) {
curC = str[i];
} else if(str[i] != curC) {
hasTwoC = true;
}
}
}
LL res = 0;
if(curC == 'A'-1) { // all ?
res = (n/step)*maxv*(m-t+1);
} else if(hasTwoC) {
res = 0;
} else {
res = (n/step)*v[curC-'A']*(m-t+1);
}
// DEBUG_FMT("solve(pos = %d, t = %d): res = %lld, step = %d\n", pos, t, res, step);
LL temp = 0;
for(int j = 0, i = pos; j < p; j++, i = (i+step)%n) {
temp += solve(i, t+1);
}
return max(temp, res);
}
int main()
{
// freopen("1.in", "r", stdin);
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
p = 2;
while(n%p) p++;
int temp = n;
while(temp > 1 && temp%p == 0) {
temp /= p;
m++;
}
cin >> str;
cin >> all;
for(int i = 1; i <= all; i++) {
char c; cin >> c;
cin >> v[c-'A'];
maxv = max(maxv, v[c-'A']);
}
cout << solve(0, 0) << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3432kb
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: 3396kb
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: 3428kb
input:
2 AB 2 A 1 B 2
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3436kb
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