QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#176300#6635. Strange KeyboardmaoyitingWA 89ms165660kbC++141.2kb2023-09-11 14:54:122023-09-11 14:54:12

Judging History

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

  • [2023-09-11 14:54:12]
  • 评测
  • 测评结果:WA
  • 用时:89ms
  • 内存:165660kb
  • [2023-09-11 14:54:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int t,n,m,k,L,len[N],d[N<<2],v[N<<2],tot,ch[N][26],mn[N],f[N];
char a[N];
string s[N];
priority_queue<pair<int,int> >q;
void calc(){
	for(int i=0;i<=len[L]*2+k;i++) d[i]=1e9,v[i]=0;
	q.push({d[0]=0,0});
	while(q.size()){
		int x=q.top().second;q.pop();
		if(v[x]) continue; v[x]=1;
		int y=x+k;
		if(y<=len[L]*2+k&&d[y]>d[x]+1) d[y]=d[x]+1,q.push({-d[y],y});
		for(int i=1;i<=L;i++){
			int y=x-len[i];
			if(y>=1&&d[y]>d[x]+1) d[y]=d[x]+1,q.push({-d[y],y});
		}
	}
}
signed main(){
	scanf("%d",&t),mn[0]=1e9;
	while(t--){
		scanf("%d%d",&m,&k);
		for(int i=1;i<=m;i++)
			scanf("%s",a),s[i]=a,len[i]=s[i].size();
		sort(len+1,len+1+m),L=unique(len+1,len+1+m)-len-1;
		calc();
		for(int i=1;i<=tot;i++) fill(ch[i],ch[i]+26,0);
		tot=1;
		for(int i=1;i<=m;i++){
			int p=1,k,len=s[i].size();
			for(int j=1;j<=len;j++){
				if(!ch[p][k=s[i][j-1]-'a']) mn[ch[p][k]=++tot]=1e9;
				p=ch[p][k],mn[p]=min(mn[p],1+d[len-j]);
			}
		}
		scanf("%s",a+1),n=strlen(a+1);
		fill(f+1,f+1+n,1e9);
		for(int i=1;i<=n;i++){
			int p=1;
			for(int j=i;j<=n;j++)
				p=ch[p][a[j]-'a'],f[j]=min(f[j],f[i-1]+mn[p]);
		}
		printf("%d\n",f[n]<1e9?f[n]:-1);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 46032kb

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: 46ms
memory: 47020kb

input:

1
1413 4867
yumnkkghwtqnhpmmsbfwypcwudihegsvtdaykueuqozagpgdnhbwzoqrqswyctzonwmjdjmmpyzbyihhpyznmqltcuckqmcybbdafoexqztxhzlfjowznisnxtgoiqjztogldyegajmegalqgawrzotuntocmsagvkzdnwhmaewuxiuhvintpzwyrkgapnmegpveyuuorrfvrfakjyetfaoqtvwghlslsvmahrkvzkwpaviufknrpuapicqdnn
yumnkkghwtqnhpmmsbfwypcwudihegsvt...

output:

10

result:

ok 1 number(s): "10"

Test #3:

score: 0
Accepted
time: 32ms
memory: 44972kb

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: 81ms
memory: 44516kb

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: 89ms
memory: 78368kb

input:

1
7 4864
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

205

result:

ok 1 number(s): "205"

Test #6:

score: 0
Accepted
time: 56ms
memory: 72784kb

input:

10
7 4923
baaabbabbbabbbbbabaabaabababbabbaaaabbaaabbbbabbaaababaaaaabaaabbabbbabbaaaabbaabbbaabbaaababaaababbabaababbaababbabaaabaabbaaabaaaababbabbabaabaabaabaabbbbaabaabbbaababbabbabaaaabbbaabbbaaaabaaaaababbaabaaaaababbbbaaaabbbaababbaabbabaabaaaaababaababaabaaaaabababababbabbbabababaaabaababbaa...

output:

4287
228
3671
549
129
372
475
534
336
288

result:

ok 10 numbers

Test #7:

score: 0
Accepted
time: 64ms
memory: 48676kb

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
-1
442
1839
2
5
31
26
122
696
280
77
1
839
11
273
7
178
421
228
6
6
82
116
1
-1
293
519
5
160
15
126
13
31
619
4...

result:

ok 100 numbers

Test #8:

score: -100
Wrong Answer
time: 69ms
memory: 165660kb

input:

1
1 5000
abaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

-1

result:

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