QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#433071 | #6635. Strange Keyboard | ucup-team3215 | TL | 105ms | 207924kb | C++20 | 1.7kb | 2024-06-07 23:38:38 | 2024-06-07 23:38:38 |
Judging History
answer
#include <algorithm>
#include <array>
#include <cstdint>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
constexpr int A = 26, V = 26e6 + 1, K = 5e3;
int nx[V], cost[V], used = V, ks[K];
int64_t ans[K + 1];
int main() {
cin.tie(0)->sync_with_stdio(0);
for (int tc = (cin >> tc, tc); tc--; ) {
fill_n(cost, used, 1e9);
fill_n(nx, used, 0);
used = 1;
fill(ks + 1, end(ks), 1e9);
fill(ans + 1, end(ans), 1e18);
int n, k; cin >> n >> k;
vector<string> v(n);
for (auto& s: v) cin >> s;
{
priority_queue pq{greater{}, vector<array<int, 2>>{{1}}};
vector<uint32_t> cost(k, -1);
for (auto& s: v) cost[s.size() % k] = min(cost[s.size() % k], {s.size() / k + 1});
while (pq.size()) {
auto [c, l] = pq.top(); pq.pop();
if (!l || c == ks[l])
for (int s = 0; s < k; ++s) if (~cost[k] && ks[(l + s) % k] > c + cost[k] + (l + s) / k) {
pq.push({ks[(l + s) % k] = c + cost[k] + (l + s) / k, (l + s) % k});
}
}
reverse(ks + 1, ks + k);
}
for (auto& s: v) {
int v = 0;
for (int rem = s.size(); auto& c: s) {
if (!nx[v]) nx[v] = used, used += A;
v = nx[v] + c - 'a';
--rem;
cost[v] = min(cost[v], ks[rem % k] + rem / k);
}
}
string s; cin >> s;
for (int i = 0; i < s.size(); ++i) {
int v = 0;
for (int j = i; j < s.size(); ++j) {
v = nx[v] + s[j] - 'a';
if (cost[v] == 1e9) break;
ans[j + 1] = min(ans[j + 1], ans[i] + cost[v] + 1);
}
}
cout << (ans[s.size()] < 1e18? ans[s.size()]: -1) << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 30ms
memory: 207020kb
input:
2 2 3 defgh abc abcde 1 1 a b
output:
3 -1
result:
ok 2 number(s): "3 -1"
Test #2:
score: 0
Accepted
time: 68ms
memory: 207924kb
input:
1 1413 4867 yumnkkghwtqnhpmmsbfwypcwudihegsvtdaykueuqozagpgdnhbwzoqrqswyctzonwmjdjmmpyzbyihhpyznmqltcuckqmcybbdafoexqztxhzlfjowznisnxtgoiqjztogldyegajmegalqgawrzotuntocmsagvkzdnwhmaewuxiuhvintpzwyrkgapnmegpveyuuorrfvrfakjyetfaoqtvwghlslsvmahrkvzkwpaviufknrpuapicqdnn yumnkkghwtqnhpmmsbfwypcwudihegsvt...
output:
10
result:
ok 1 number(s): "10"
Test #3:
score: 0
Accepted
time: 105ms
memory: 206976kb
input:
10 446 4905 afigcjhcgagabbiccehjcjajigghgbjjadccicghggijjdfeciaccgheedjdhgfjdfdbgidbbdjaiehhceeehchhabhaideggjbjajgfgicfdggahhbjgdebccbgbiedhehaebdccdfdffaacjcfbgjeegbahhbgcdjigijajheidchbddicehhhjbeiaajgedhdcjiefdgdbjjfaegheeidieheecaicciaajbabiidcecefgiicccdidegeica afigcjhcgagabbiccehjcjajigghgbj...
output:
3 2 2 11 6 5 1 1 1 1
result:
ok 10 numbers
Test #4:
score: -100
Time Limit Exceeded
input:
100 140 4879 baabaababbababbaabababaaababbbabbbbbbabbababbbabbbbabbbbbbaabbbbbbbbabaabbbaabaabbbaabbabaabaabbbabbbababbbaabbabaaaaabbaaabbbabb baa baabaababbababbaabababaaababbbabbbbbbabbab baabaababbababbaabababaaabab baabaababbababbaabababaaababbbabbb baabaababbababbaabababaaababbbabbbbbbabbababbb...