QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#203178 | #2476. Pizzo Collectors | Team_name# | WA | 1ms | 3992kb | C++20 | 1.5kb | 2023-10-06 15:59:21 | 2023-10-06 15:59:22 |
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;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3992kb
input:
8 ?A?B?A?C 3 A 1 B 1000 C 100000
output:
0
result:
wrong answer 1st lines differ - expected: '1301004', found: '0'