QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212071#6635. Strange KeyboardMIT01WA 121ms145740kbC++142.3kb2023-10-13 07:19:202023-10-13 07:19:20

Judging History

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

  • [2023-10-13 07:19:20]
  • 评测
  • 测评结果:WA
  • 用时:121ms
  • 内存:145740kb
  • [2023-10-13 07:19:20]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define SZ 666666
typedef long long ll;
int T,n,k,m;
char t[300009];
ll gj[300009],d[3000009];
ll good[3200999];
int ch[3200999][26],an=0;
bool vv[300009];
string ss[3300999];
const ll inf = 1e17;
void sol() {
    an=1;
    cin>>n>>k;
    for (int i = 0; i <= k; i++)    
        gj[i] = inf, vv[i] = 0;
    for(int i=1;i<=n;++i) {
        string s;
        cin>>s;
        int id = s.size() % k;
        ll V=(s.size()-s.size()%k)/k+1;
        if(gj[id] > V) 
            gj[id] = V;
        ss[i]=s;
    }
    gj[0]=0;
    vector<int> v;
    
    priority_queue<pair<ll,int>> s;
    for(int i=0;i<k;++i) 
        if(gj[i]<inf) 
            s.push(make_pair(-gj[i], i)), v.push_back(i);
    // s.push(make_pair(-gj[0],0));
    while(s.size()) {
        auto t=s.top().second; s.pop();
        if(vv[t]) continue; vv[t]=1;
        for(auto j : v) {
            int z=t+j; ll v=gj[j]+gj[t];
            while (z>=k) z-=k, ++v;
            if(v>=gj[z]) continue;
            gj[z]=v; s.push(make_pair(-gj[z],z));
//            gj[z]=min(gj[z],v);
        }
    }
    memset(vv,0,sizeof vv);
    memset(ch[0], 0, sizeof(ch[0]));
    good[0] = inf;
    for(int i=1;i<=n;++i) {
        string s=ss[i];
        int o=1;
        for(int j=0;j<s.size();++j) {
			assert(islower(s[j]));
            int c=s[j]-'a';
            if(!ch[o][c]) {
                ch[o][c]=++an;
                good[an] = inf;
                for (int j = 0; j < 26; j++) ch[an][j] = 0;
            }
            o=ch[o][c];
            ll t=(s.size()-j-1)%k;
            ll w=1+((ll)s.size()-j-1)/k;
            if(t) w+=gj[k-t]+1;
            good[o]=min(good[o],w);
        }
    }
    scanf("%s", t+1);
    m=strlen(t+1);
    assert(m <= 5000);
    assert(m > 0);
    for (int i = 0; i <= m; i++) d[i] = inf;
    d[0]=0;
    for(int x=0;x<=m;++x) {
        int o=1;
        for(int j=x+1;j<=m;++j) {
			assert(islower(t[j]));
            o=ch[o][t[j]-'a'];
            if(o) d[j]=min(d[j],d[x]+good[o]); else break;
        }
    }
    ll aa=d[m];
    if(aa>=inf / 2) aa=-1;
    cout<<aa<<"\n";
}
int main() {
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    cin>>T;
    while(T--) sol();
    return 0;
}
/*

2
2 3
defgh
abc
abcde
1 1
a
b

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 13ms
memory: 113800kb

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: 34ms
memory: 115032kb

input:

1
1413 4867
yumnkkghwtqnhpmmsbfwypcwudihegsvtdaykueuqozagpgdnhbwzoqrqswyctzonwmjdjmmpyzbyihhpyznmqltcuckqmcybbdafoexqztxhzlfjowznisnxtgoiqjztogldyegajmegalqgawrzotuntocmsagvkzdnwhmaewuxiuhvintpzwyrkgapnmegpveyuuorrfvrfakjyetfaoqtvwghlslsvmahrkvzkwpaviufknrpuapicqdnn
yumnkkghwtqnhpmmsbfwypcwudihegsvt...

output:

10

result:

ok 1 number(s): "10"

Test #3:

score: 0
Accepted
time: 54ms
memory: 114768kb

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: 121ms
memory: 113532kb

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: 83ms
memory: 145740kb

input:

1
7 4864
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

205

result:

ok 1 number(s): "205"

Test #6:

score: -100
Wrong Answer
time: 48ms
memory: 137352kb

input:

10
7 4923
baaabbabbbabbbbbabaabaabababbabbaaaabbaaabbbbabbaaababaaaaabaaabbabbbabbaaaabbaabbbaabbaaababaaababbabaababbaababbabaaabaabbaaabaaaababbabbabaabaabaabaabbbbaabaabbbaababbabbabaaaabbbaabbbaaaabaaaaababbaabaaaaababbbbaaaabbbaababbaabbabaabaaaaababaababaabaaaaabababababbabbbabababaaabaababbaa...

output:

4287
238
2978
553
135
227
513
484
347
312

result:

wrong answer 2nd numbers differ - expected: '228', found: '238'