QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#550102 | #2481. Pickpockets | XfJbUhpyzgaW# | WA | 2ms | 8252kb | C++14 | 1.4kb | 2024-09-07 09:46:49 | 2024-09-07 09:46:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
using ll = long long;
int n, p, m, k;
char str[N];
int value[28];
vector<ll> dp[N];
vector<int> col[N];
ll pw[N];
int merge(int x, int y) {
if (x == 26 || y == 26) return x ^ y ^ 26;
if (x == y) return x;
return 27;
}
int main() {
cin >> n >> str >> k;
for (int i = 0; i < k; i++) {
string ch;
int val;
cin >> ch >> val;
value[ch[0] - 'A'] = val;
value[26] = max(value[26], value[i]);
}
for (int i = 2; i <= n; i++) if (n % i == 0) { p = i; break; }
for (int x = 1; x <= n; x *= p)
pw[m++] = x;
m--;
for (int i = 0; i <= m; i++) {
dp[i].resize(pw[i]);
col[i].resize(pw[i]);
}
for (int i = 0; i < n; i++) {
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 k = 0; k < pw[i + 1]; k += pw[i]) {
col[i][j] = merge(col[i][j], col[i + 1][j + k]);
dp[i][j] += dp[i + 1][j + k];
}
dp[i][j] = max(dp[i][j], value[col[i][j]] * pw[m - i] * (m - i + 1));
}
}
cout << dp[0][0] << "\n";
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 8252kb
input:
2 2 1 2 1 5 2 5
output:
1
result:
wrong answer 1st lines differ - expected: '10', found: '1'