QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211334#6635. Strange KeyboardAFewSunsWA 56ms65848kbC++142.7kb2023-10-12 15:05:252023-10-12 15:05:26

Judging History

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

  • [2023-10-12 15:05:26]
  • 评测
  • 测评结果:WA
  • 用时:56ms
  • 内存:65848kb
  • [2023-10-12 15:05:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 8e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
ll T,n,m,k,len[1000010],lsh[1000010],cnt=0;
ll dis[1005010],g[5050],f[5050];
ll ch[1000010][26],h[1000010],rt=1,tot=1;
char s[1000010],t[5050];
void bfs(){
	fr(i,0,n+k-1) dis[i]=inf;
	dis[0]=0;
	queue<ll> q;
	q.push(0);
	while(!q.empty()){
		ll u=q.front();
		q.pop();
		if(u>=k){
			if(dis[u-k]>(dis[u]+1)){
				dis[u-k]=dis[u]+1;
				q.push(u-k);
			}
		}
		else{
			fr(i,1,cnt){
				if(dis[u+lsh[i]]>(dis[u]+1)){
					dis[u+lsh[i]]=dis[u]+1;
					q.push(u+lsh[i]);
				}
			}
		}
	}
	g[0]=0;
	fr(i,1,k-1){
		if(dis[k-i]==inf) g[i]=inf;
		else g[i]=dis[k-i]+1;
	}
}
il void clr(){
	fr(i,1,tot) fr(j,0,25) ch[i][j]=0;
	rt=tot=1;
	cnt=0;
}
int main(){
	T=read();
	while(T--){
		n=read();
		k=read();
		fr(i,1,n){
			scanf("%s",s+len[i-1]+1);
			len[i]=len[i-1]+strlen(s+len[i-1]+1);
			lsh[++cnt]=len[i]-len[i-1];
		}
		sort(lsh+1,lsh+cnt+1);
		cnt=unique(lsh+1,lsh+cnt+1)-lsh-1;
		bfs();
		fr(i,1,n){
			ll x=rt;
			fr(j,len[i-1]+1,len[i]){
				if(!ch[x][s[j]-'a']){
					ch[x][s[j]-'a']=++tot;
					h[tot]=inf;
				}
				x=ch[x][s[j]-'a'];
				h[x]=min(h[x],(len[i]-j)/k+g[(len[i]-j)%k]+1);
			}
		}
		scanf("%s",t+1);
		m=strlen(t+1);
		fr(i,1,m) f[i]=inf;
		f[0]=0;
		fr(i,0,m-1){
			ll x=rt;
			fr(j,i+1,m){
				if(!ch[x][t[j]-'a']) break;
				x=ch[x][t[j]-'a'];
				f[j]=min(f[j],f[i]+h[x]);
			}
		}
		if(f[m]==inf) writeln(-1);
		else writeln(f[m]);
		clr();
	}
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7820kb

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: 8ms
memory: 8820kb

input:

1
1413 4867
yumnkkghwtqnhpmmsbfwypcwudihegsvtdaykueuqozagpgdnhbwzoqrqswyctzonwmjdjmmpyzbyihhpyznmqltcuckqmcybbdafoexqztxhzlfjowznisnxtgoiqjztogldyegajmegalqgawrzotuntocmsagvkzdnwhmaewuxiuhvintpzwyrkgapnmegpveyuuorrfvrfakjyetfaoqtvwghlslsvmahrkvzkwpaviufknrpuapicqdnn
yumnkkghwtqnhpmmsbfwypcwudihegsvt...

output:

10

result:

ok 1 number(s): "10"

Test #3:

score: 0
Accepted
time: 19ms
memory: 5920kb

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: 55ms
memory: 5812kb

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: -100
Wrong Answer
time: 56ms
memory: 65848kb

input:

1
7 4864
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

-4893488147419103232

result:

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