QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#168256 | #2476. Pizzo Collectors | LaStataleBlue# | RE | 0ms | 1884kb | C++14 | 1.2kb | 2023-09-08 01:53:04 | 2023-09-08 01:53:05 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
constexpr int MAXN = 100'005;
char s[MAXN];
int n, prime, ln;
int pizzo[100];
int maxpizzo;
pair<ll, char> util(const int x, const int d, const int y)
{
if (d == n)
return {pizzo[(int)s[x]], s[x]};
ll ans = 0;
char cchar = '?';
for (int i = 0; i < prime; i++)
{
const auto r = util((x + i * d) % n, d * prime, y + 1);
ans += r.first;
if (r.second == '?')
;
else if (cchar == '?')
cchar = r.second;
else if (r.second != cchar)
cchar = '!';
}
int val = 0;
if (cchar == '?')
val = maxpizzo;
else if (cchar != '!')
val = pizzo[(int)cchar];
return {max(ans, (ll)val * (ln - y + 1) * n / d), cchar};
}
int main()
{
int n, k;
scanf("%d %s %d", &n, s, &k);
::n = n;
maxpizzo = 0;
for (int i = 0; i < k; i++)
{
char c;
int v;
scanf(" %c %d ", &c, &v);
pizzo[(int)c] = v;
maxpizzo = max(maxpizzo, v);
}
pizzo['?'] = maxpizzo;
prime = 2;
for (int i = 2; i < n; i++)
if (n % i == 0)
{
prime = i;
break;
}
ln = 0;
for (int i = prime; i <= n; i *= prime)
ln++;
printf("%lld\n", util(0, 1, 0).first);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 1700kb
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: 1884kb
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: 1752kb
input:
2 AB 2 A 1 B 2
output:
3
result:
ok single line: '3'
Test #4:
score: -100
Runtime Error
input:
7 ??????? 3 A 1 B 3 C 2