QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#210962#6635. Strange KeyboardzyxawaWA 7ms137580kbC++141.7kb2023-10-11 21:57:012023-10-11 21:57:02

Judging History

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

  • [2023-10-11 21:57:02]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:137580kb
  • [2023-10-11 21:57:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int p,n,m,k,tot=1000000,t[1000001][26],vis[5001];
long long dis[5001],dp[5001],val[1000001];
vector <int> str[1000001];
char s[1000001];
map <int,int> len;
priority_queue <pair<long long,int>,vector<pair<long long,int> >,greater<pair<long long,int> > > q;
void insert(int d){
	int p=0,cnt=str[d].size(),now=0;
	for(auto i:str[d]){
		if(!t[p][i]) t[p][i]=++tot;
		p=t[p][i],now++,val[p]=min(val[p],(cnt-now)/k+dis[(k-(cnt-now)%k)%k]+((k-(cnt-now)%k)%k!=0));
//		cout<<now<<" "<<(cnt-now)/k<<" "<<(cnt-now)%k<<" "<<(cnt-now)/k+dis[(k-(cnt-now)%k)%k]+1<<endl;
	}
//	val[p]=0;
}
int main(){
	scanf("%d",&p);
	while(p--){
		scanf("%d%d",&n,&k),len.clear();
		for(int i=1;i<=n;i++) str[i].clear();
		for(int i=0;i<=tot;i++) val[i]=1e16,memset(t[i],0,sizeof(t[i]));
		for(int i=0;i<=5000;i++) dp[i]=dis[i]=1e16,tot=vis[i]=0;
		for(int i=1;i<=n;i++){
			scanf("%s",s+1),m=strlen(s+1);
			if(!len.count(m%k)) len[m%k]=m/k+1;
			else len[m%k]=min(len[m%k],m/k+1);
			for(int j=1;j<=m;j++) str[i].push_back(s[j]-97);
		}
		scanf("%s",s+1),m=strlen(s+1),dp[0]=dis[0]=0;
		q.push({0,0});
		while(!q.empty()){
			int x=q.top().second;
			q.pop();
			if(vis[x]) continue;
			vis[x]=1;
			for(auto i:len){
				int y=(x+i.first)%k,w=(x+i.first>=k);
				if(dis[y]>dis[x]+i.second+w) dis[y]=dis[x]+i.second+w,q.push({dis[y],y});
			}
		}
		for(int i=1;i<=n;i++) insert(i);
		for(int i=0;i<m;i++){
			for(int j=i+1,p=0;j<=m;j++){
				if(!t[p][s[j]-97]) break;
				p=t[p][s[j]-97];
				cout<<val[p]<<endl;
				dp[j]=min(dp[j],dp[i]+val[p]+1);
			}
		}
		if(dp[m]>=1e16) printf("-1\n");
		else printf("%lld\n",dp[m]);
	}
	return 0;
}
/*
abc abc defgh

2
2 3
defgh
abc
abcde
1 1
a
b
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 137580kb

input:

2
2 3
defgh
abc
abcde
1 1
a
b

output:

6
3
0
4
1
3
-1

result:

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