QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#550141 | #2476. Pizzo Collectors | XfJbUhpyzgaW# | RE | 0ms | 3736kb | C++14 | 1.9kb | 2024-09-07 10:02:04 | 2024-09-07 10:02:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
using ll = long long;
int n, p, m, k;
string str;
int value[30];
vector<ll> dp[30];
vector<int> col[30];
ll pw[30];
int merge(int x, int y) {
if (x == 27 || y == 27) return 27;
if (x == 26) return y;
if (y == 26) return x;
if (x == y) return x;
return 27;
}
int main() {
cin >> n >> str >> k;
if (n > 1e5 || k > 26 || str.size() != n) {
cout << "Fuck you";
return 0;
}
for (int i = 0; i < k; i++) {
string ch;
int val;
cin >> ch >> val;
if (ch[0] < 'A' || ch[0] > 'Z') {
cout << "Fuck you";
return 0;
}
value[ch[0] - 'A'] = val;
value[26] = max(value[26], val);
}
for (int i = 2; i <= n; i++) if (n % i == 0) { p = i; break; }
if (n == 1) p = 1;
for (int x = 1, i = 0; x <= n; x *= p, i++)
pw[m = i] = x;
if (pw[m] != n) {
cout << "Fuck you";
return 0;
}
for (int i = 0; i <= m; i++) {
dp[i].resize(pw[i]);
col[i].resize(pw[i]);
}
for (int i = 0; i < n; i++) {
if (str[i] != '?' && (str[i] < 'A' || str[i] > 'Z')) {
cout << "Fuck you";
return 0;
}
col[m][i] = (str[i] == '?' ? 26 : str[i] - 'A');
dp[m][i] = value[col[m][i]];
}
for (int i = m - 1; i >= 0; i--) {
for (int j = 0; j < pw[i]; j++)
col[i][j] = 26, dp[i][j] = 0;
for (int j = 0; j < pw[i + 1]; j++) {
col[i][j % pw[i]] = merge(col[i][j % pw[i]], col[i + 1][j]);
dp[i][j % pw[i]] += dp[i + 1][j];
}
for (int j = 0; j < pw[i]; j++)
dp[i][j] = max(dp[i][j], value[col[i][j]] * pw[m - i] * (m - i + 1));
}
cout << dp[0][0] << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
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: 3464kb
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: 3736kb
input:
2 AB 2 A 1 B 2
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
7 ??????? 3 A 1 B 3 C 2
output:
42
result:
ok single line: '42'
Test #5:
score: -100
Runtime Error
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