QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#553726#1193. Ambiguous EncodingccccccydWA 0ms3612kbC++141.4kb2024-09-08 19:03:172024-09-08 19:03:22

Judging History

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

  • [2024-09-08 19:03:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-09-08 19:03:17]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define mk make_pair
#define ph push_back
#define rep(i,l,r) for(int i(l),i##end(r);i<=i##end;++i)
#define per(i,r,l) for(int i(r),i##end(l);i>=i##end;--i)
using namespace std;
const int N=52; const ll inf=1e18;
int n,m,len[N]; char s[N][N];
inline bool chk(int x,int d,int y,int len){
	rep(i,1,len) if(s[x][d+i]!=s[y][i]) return 0;
	return 1;
}
queue<pair<int,int>> q; bool in[N][N]; ll f[N][N],ans=inf; 
inline void ins(int i,int j,int x){
	if(x<f[i][j]){
		f[i][j]=x;
		if(!in[i][j]) in[i][j]=1,q.push(mk(i,j));
	}
}
signed main(){
//	freopen("bad.in", "r", stdin);
//	freopen("bad.out", "w", stdout);
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%s",s[i]+1),len[i]=strlen(s[i]+1);
	
	rep(i,1,n) rep(j,0,m) f[i][j]=inf;
	rep(i,1,n) ins(i,0,0);
	while(!q.empty()){
		int x=q.front().first,d=q.front().second; q.pop();
//		printf("%d %d  %lld\n",x,d,f[x][d]);
		in[x][d]=0;
		rep(y,1,n) if((d||x!=y)&&chk(x,d,y,min(len[x]-d,len[y]))) {
//			printf("%d %d  %d   %d %lld\n",x,d,y,min(len[x]-d,len[y]),f[x][d]+min(len[x]-d,len[y])); 
			if(len[x]-d==len[y]){
				ans=min(ans,f[x][d]+min(len[x]-d,len[y]));
			}else{
				if(len[x]-d>len[y]){
					ins(x,d+len[y],f[x][d]+min(len[x]-d,len[y]));
				}else{
					ins(y,len[x]-d,f[x][d]+min(len[x]-d,len[y]));
				}
			}
		}
	}
	if(ans==inf) puts("-1");
	else cout<<ans;
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3612kb

input:

3
0
01
10

output:

-1

result:

wrong answer expected '3', found '-1'