QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#217046 | #6635. Strange Keyboard | CharlieVinnie | WA | 1ms | 3516kb | C++17 | 1.8kb | 2023-10-16 12:54:58 | 2023-10-16 12:54:59 |
Judging History
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) For(_,0,1) For(i,0,K-1) dis[(i+k)%K]=min(dis[(i+k)%K],dis[i]+has[k]+(i+k>=K));
debug(has); debug(dis);
vector<array<int,26>> son(2); vector<int> g(2);
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[(K-(sz-1-j)%K)%K]+1+(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: 0
Wrong Answer
time: 1ms
memory: 3516kb
input:
2 2 3 defgh abc abcde 1 1 a b
output:
5 -1
result:
wrong answer 1st numbers differ - expected: '3', found: '5'