QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#433072 | #6635. Strange Keyboard | ucup-team3215 | WA | 874ms | 207884kb | C++20 | 1.7kb | 2024-06-07 23:41:16 | 2024-06-07 23:41:18 |
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[s] && ks[(l + s) % k] > c + cost[s] + (l + s) / k) {
pq.push({ks[(l + s) % k] = c + cost[s] + (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';
}
}
详细
Test #1:
score: 100
Accepted
time: 8ms
memory: 206708kb
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: 42ms
memory: 207884kb
input:
1 1413 4867 yumnkkghwtqnhpmmsbfwypcwudihegsvtdaykueuqozagpgdnhbwzoqrqswyctzonwmjdjmmpyzbyihhpyznmqltcuckqmcybbdafoexqztxhzlfjowznisnxtgoiqjztogldyegajmegalqgawrzotuntocmsagvkzdnwhmaewuxiuhvintpzwyrkgapnmegpveyuuorrfvrfakjyetfaoqtvwghlslsvmahrkvzkwpaviufknrpuapicqdnn yumnkkghwtqnhpmmsbfwypcwudihegsvt...
output:
10
result:
ok 1 number(s): "10"
Test #3:
score: 0
Accepted
time: 128ms
memory: 206956kb
input:
10 446 4905 afigcjhcgagabbiccehjcjajigghgbjjadccicghggijjdfeciaccgheedjdhgfjdfdbgidbbdjaiehhceeehchhabhaideggjbjajgfgicfdggahhbjgdebccbgbiedhehaebdccdfdffaacjcfbgjeegbahhbgcdjigijajheidchbddicehhhjbeiaajgedhdcjiefdgdbjjfaegheeidieheecaicciaajbabiidcecefgiicccdidegeica afigcjhcgagabbiccehjcjajigghgbj...
output:
3 2 2 11 6 5 1 1 1 1
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 874ms
memory: 207028kb
input:
100 140 4879 baabaababbababbaabababaaababbbabbbbbbabbababbbabbbbabbbbbbaabbbbbbbbabaabbbaabaabbbaabbabaabaabbbabbbababbbaabbabaaaaabbaaabbbabb baa baabaababbababbaabababaaababbbabbbbbbabbab baabaababbababbaabababaaabab baabaababbababbaabababaaababbbabbb baabaababbababbaabababaaababbbabbbbbbabbababbb...
output:
1 1 1 1 3 1 1 1 1 1 1 3 2 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 4 3 2 1 2 1 1 1 1 1 2 1 1 1 3 1 1 1 2 1 1 1 2 3 1 1 1 2 1 1 1 1 1 1 1 1 3 2 3 1 3 1 1 2 1 2 3 2 1 1 1 3 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 4 1
result:
ok 100 numbers
Test #5:
score: 0
Accepted
time: 100ms
memory: 207716kb
input:
1 7 4864 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
205
result:
ok 1 number(s): "205"
Test #6:
score: -100
Wrong Answer
time: 123ms
memory: 207228kb
input:
10 7 4923 baaabbabbbabbbbbabaabaabababbabbaaaabbaaabbbbabbaaababaaaaabaaabbabbbabbaaaabbaabbbaabbaaababaaababbabaababbaababbabaaabaabbaaabaaaababbabbabaabaabaabaabbbbaabaabbbaababbabbabaaaabbbaabbbaaaabaaaaababbaabaaaaababbbbaaaabbbaababbaabbabaabaaaaababaababaabaaaaabababababbabbbabababaaabaababbaa...
output:
4287 228 3671 549 129 356 475 532 336 287
result:
wrong answer 6th numbers differ - expected: '372', found: '356'