QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#550115#2476. Pizzo CollectorsXfJbUhpyzgaW#RE 0ms3600kbC++141.5kb2024-09-07 09:52:522024-09-07 09:52:53

Judging History

你现在查看的是最新测评结果

  • [2024-09-07 09:52:53]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3600kb
  • [2024-09-07 09:52:52]
  • 提交

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[30];
vector<int> col[30];
ll pw[30];

int merge(int x, int y) {
    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[n]) {
        cout << "Fuck you";
        return 0;
    }
    for (int i = 0; i < k; i++) {
        string ch;
        int val;
        cin >> ch >> val;
        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; }

    for (int x = 1; x <= n; x *= p)
        pw[m++] = x;
    m--;

    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++) {
        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: 100
Accepted
time: 0ms
memory: 3580kb

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: 3600kb

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: 3412kb

input:

2
AB
2
A 1
B 2

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3512kb

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

output:


result: