QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#217083#6635. Strange KeyboardCharlieVinnieWA 62ms60932kbC++171.9kb2023-10-16 14:30:312023-10-16 14:30:31

Judging History

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

  • [2023-10-16 14:30:31]
  • 评测
  • 测评结果:WA
  • 用时:62ms
  • 内存:60932kb
  • [2023-10-16 14:30:31]
  • 提交

answer

// #define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
#ifdef DEBUG
#include "PrettyDebug.hpp"
#else
#define debug(...) [](auto...){}(__VA_ARGS__)
#endif
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define assume(expr) ((!!(expr))||(exit((fprintf(stderr,"Assumption Failed: %s on Line %d\n",#expr,__LINE__),-1)),false))
#define range basic_string_view
using namespace std; typedef long long ll;
void solve(){
    int n,K; cin>>n>>K; vector<int> has(K,1e9); vector<string> s(n+1);
    For(i,1,n) cin>>s[i],has[s[i].size()%K]=min(has[s[i].size()%K],int(s[i].size())/K+1);
    vector<int> dis(K,1e9); dis[0]=0;
    For(k,1,K-1) if(has[k]!=1e9){
        int g=__gcd(k,K);
        For(i,0,g-1){
            int u=i; For(_,1,2*K/g) dis[(u+k)%K]=min(dis[(u+k)%K],dis[u]+has[k]+(u+k>=K));
        }
    }
    debug(has); debug(dis);
    vector<array<int,26>> son(2); vector<int> g(2);
    reverse(dis.begin()+1,dis.end()); For(i,1,K-1) dis[i]++;
    For(i,1,n){
        int u=1,sz=s[i].size();
        For(j,0,sz-1){
            int c=s[i][j]-'a'; if(!son[u][c]) son[u][c]=son.size(),son.push_back(array<int,26>()),g.push_back(1e9);
            u=son[u][c]; g[u]=min(g[u],1+dis[(sz-1-j)%K]+(sz-1-j)/K);
        }
    }
    string T; cin>>T; T=' '+T; int m=T.size()-1; vector<int> f(m+1,1e9); f[0]=0;
    For(i,0,m-1){
        int u=1; For(j,i+1,m){
            if(!(u=son[u][T[j]-'a'])) break;
            f[j]=min(f[j],f[i]+g[u]);
        }
    }
    debug(f);
    cout<<(f[m]==1e9?-1:f[m])<<'\n';
}
signed main(){
    atexit([](){cerr<<"Time = "<<clock()<<" ms"<<endl;});
    int T; cin>>T; while(T--) solve();
    return 0;
}

// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
// CONTINUE, NON-STOPPING, FOR CHARLIEVINNIE

// Started Coding On: October 16 Mon, 11 : 34 : 02

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3744kb

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: 21ms
memory: 5368kb

input:

1
1413 4867
yumnkkghwtqnhpmmsbfwypcwudihegsvtdaykueuqozagpgdnhbwzoqrqswyctzonwmjdjmmpyzbyihhpyznmqltcuckqmcybbdafoexqztxhzlfjowznisnxtgoiqjztogldyegajmegalqgawrzotuntocmsagvkzdnwhmaewuxiuhvintpzwyrkgapnmegpveyuuorrfvrfakjyetfaoqtvwghlslsvmahrkvzkwpaviufknrpuapicqdnn
yumnkkghwtqnhpmmsbfwypcwudihegsvt...

output:

10

result:

ok 1 number(s): "10"

Test #3:

score: 0
Accepted
time: 26ms
memory: 4236kb

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: 61ms
memory: 4032kb

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: 62ms
memory: 60932kb

input:

1
7 4864
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

205

result:

ok 1 number(s): "205"

Test #6:

score: -100
Wrong Answer
time: 32ms
memory: 51312kb

input:

10
7 4923
baaabbabbbabbbbbabaabaabababbabbaaaabbaaabbbbabbaaababaaaaabaaabbabbbabbaaaabbaabbbaabbaaababaaababbabaababbaababbabaaabaabbaaabaaaababbabbabaabaabaabaabbbbaabaabbbaababbabbabaaaabbbaabbbaaaabaaaaababbaabaaaaababbbbaaaabbbaababbaabbabaabaaaaababaababaabaaaaabababababbabbbabababaaabaababbaa...

output:

-1
-1
-1
845
-1
-1
-1
-1
-1
-1

result:

wrong answer 1st numbers differ - expected: '4287', found: '-1'