QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136076#6635. Strange KeyboardDelay_for_five_minutesWA 450ms114608kbC++202.3kb2023-08-06 23:46:272023-08-06 23:46:30

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-06 23:46:30]
  • 评测
  • 测评结果:WA
  • 用时:450ms
  • 内存:114608kb
  • [2023-08-06 23:46:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n , k;
string s[1000005];
set<int> st;
vector<pair<int,int> > E[5005];
int dis[5005];
void dij()
{
    priority_queue<pair<int,int> , vector<pair<int,int> > , greater<pair<int,int> > > pq;
    for(int i = 0;i < k;i++) dis[i] = 1e9;
    dis[0] = 0;
    pq.push(pair<int,int>{0 , 0});
    while(pq.size()) {
        int u = pq.top().second ; pq.pop();
        for(auto &[v , w] : E[u]) {
            if(dis[u] + w < dis[v]) {
                dis[v]  =dis[u] + w;
                pq.push(pair<int,int>{dis[v] , v});
            }
        }
    }
    return;
}
struct trie {
    int mn;
    int ch[26];
    void clr() {
        memset(ch,0,sizeof(ch));
        mn = 1e9;
    }
}T[1000005];
int cnt ;
inline int get(int x)
{
    return x/k + dis[x % k];
}
void ins(const string &s)
{
    int u = 0;
    for(int i = 0;i < s.size();i++) {
        int t = s[i] - 'a';
        if(!T[u].ch[t]) {
            T[u].ch[t] = ++cnt ; T[cnt].clr();
        }
        u = T[u].ch[t];
        T[u].mn = min(T[u].mn , get(s.size() - i - 1) + 1);
    }
    return;
}
ll dp[5005];
void solve()
{
    cin >> n >> k; st.clear();cnt = 0; T[0].clr();
    for(int i = 0;i < k;i++) E[i].clear();
    for(int i = 1;i <= n;i++) {
        cin >> s[i]; st.insert(s[i].size());
    }
    for(auto L : st) {
        for(int i = 0;i < k;i++) { /// (u + L) mod k = i
            int u = (i - L%k + k) % k;
            E[i].push_back(pair<int,int>{u , (u + L) / k + 1}) ;
        }
    }
    dij() ;
   // for(int i = 0;i < k;i++) printf("dist %d %d\n",i,dis[i]);
    for(int i = 1;i <= n;i++) {
        ins(s[i]);
    }
    string t;cin >> t;
    dp[0] = 0;
    for(int i = 1;i <= t.size();i++) dp[i] = 1e18;
    for(int i = 0;i < t.size();i++) {
        int u = 0;
        for(int j = i + 1;j <= t.size();j++) {
            u = T[u].ch[t[j - 1] - 'a'] ;
            if(!u) break;
            dp[j] = min(dp[j] , dp[i] + T[u].mn);
        }
    }
    if(dp[t.size()] > 1e17) cout << -1 << '\n';
    else cout << dp[t.size()] << '\n';
}
int main()
{
//    freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
    int t;cin >> t;
    while(t--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 36340kb

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: 67ms
memory: 114608kb

input:

1
1413 4867
yumnkkghwtqnhpmmsbfwypcwudihegsvtdaykueuqozagpgdnhbwzoqrqswyctzonwmjdjmmpyzbyihhpyznmqltcuckqmcybbdafoexqztxhzlfjowznisnxtgoiqjztogldyegajmegalqgawrzotuntocmsagvkzdnwhmaewuxiuhvintpzwyrkgapnmegpveyuuorrfvrfakjyetfaoqtvwghlslsvmahrkvzkwpaviufknrpuapicqdnn
yumnkkghwtqnhpmmsbfwypcwudihegsvt...

output:

10

result:

ok 1 number(s): "10"

Test #3:

score: 0
Accepted
time: 158ms
memory: 55672kb

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: 450ms
memory: 46964kb

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: 51ms
memory: 67956kb

input:

1
7 4864
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

205

result:

ok 1 number(s): "205"

Test #6:

score: 0
Accepted
time: 63ms
memory: 83020kb

input:

10
7 4923
baaabbabbbabbbbbabaabaabababbabbaaaabbaaabbbbabbaaababaaaaabaaabbabbbabbaaaabbaabbbaabbaaababaaababbabaababbaababbabaaabaabbaaabaaaababbabbabaabaabaabaabbbbaabaabbbaababbabbabaaaabbbaabbbaaaabaaaaababbaabaaaaababbbbaaaabbbaababbaabbabaabaaaaababaababaabaaaaabababababbabbbabababaaabaababbaa...

output:

4287
228
3671
549
129
372
475
534
336
288

result:

ok 10 numbers

Test #7:

score: -100
Wrong Answer
time: 110ms
memory: 51932kb

input:

100
7 4807
abbababaababbaabbabbaabaababbaaababaabaaabbaaaabababbbaabbaaabababbaabaabbaaaaabbbbaabbbaaabbbbabaabbbaaaaabbbaabbaaaabbaaababbaaabbbbabaabbababababbbabaaabaaaabbbbabbabbbbbaabaaabaababbabaaabbaabbabbabaaababbbabbabbbaababaabaaaabaaabbbbabbaabaababbbabbbbaaaabbabbbaabbaabbbbb
aaaaababaaab...

output:

45
32
11
4
2475
132
50
330
20
6
99
25
126
6
4
14
74
108
208
11
5
67
166
2822
178
1307
548
92
386
493
279
2415
255
262
567
215
46
113
31
651
17
4
8
21
12
100
69
152
15
55
521
146
11
13
181
6000001206
442
1839
2
5
31
26
122
696
280
77
1
839
11
273
7
178
421
228
6
6
82
116
1
4000000254
293
519
5
160
15...

result:

wrong answer 56th numbers differ - expected: '-1', found: '6000001206'