QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#65641 | #2476. Pizzo Collectors | UBB_Zalau00# | WA | 2ms | 3304kb | C++14 | 1.4kb | 2022-12-02 18:16:09 | 2022-12-02 18:16:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin >> n;
cin >> s;
int t;
map<char, int> cost;
cin >> t;
int best_cost = -1;
for(int i = 1;i <= t;i++){
char c;
int v;
cin >> c >> v;
cost[c] = v;
if(best_cost < v){
best_cost = v;
}
}
if(n == 1){
cout << (s[1] == '?' ? best_cost:cost[s[1]]);
return 0;
}
int p = n;
for(int i = 2;1LL * i * i <= n;i++){
if(n % i == 0){
p = i;
break;
}
}
vector<long long> dp(n, 0);
int layers = 0;
for(int current_power = n;current_power;current_power /= p){
layers++;
vector<long long> old_dp;
old_dp.swap(dp);
dp = vector<long long>(n, 0);
for(int i = 0;i < current_power;i++){
char activeChar = -1;
bool is_impossible = false;
for(int j = i;j < n;j += current_power){
dp[i] += old_dp[j];
if(s[j] != '?'){
if(activeChar == -1 || activeChar == s[j]){
activeChar = s[j];
} else {
is_impossible = true;
}
}
}
if(is_impossible){
continue;
}
int target_cost = (activeChar == -1 ? best_cost:cost[activeChar]);
dp[i] = max(dp[i], 1LL * (n / current_power) * target_cost * layers);
}
}
cout << dp[0];
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3292kb
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: 2ms
memory: 3180kb
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: 2ms
memory: 3260kb
input:
2 AB 2 A 1 B 2
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3176kb
input:
7 ??????? 3 A 1 B 3 C 2
output:
42
result:
ok single line: '42'
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 3304kb
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:
0
result:
wrong answer 1st lines differ - expected: '26', found: '0'