QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#246075#4669. Genetic ModificationsJudgelightRE 0ms0kbC++142.0kb2023-11-10 16:03:402023-11-10 16:03:41

Judging History

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

  • [2023-11-10 16:03:41]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-10 16:03:40]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=1e5+10;
char a[N],b[N];
int n,m,nex[N][2];
int f1[25][N],las1[25][N];
void solve1(int i,int j){
	if(i==1){
		printf("%d ",j);
		return;
	}
	solve1(i-1,las1[i-1][j-1]);
	printf("%d ",j);
}
void deal1(){
	if(a[1]==b[1]){
		for(int i=1;i<nex[1][a[1]^1]==0?n+1:nex[1][a[1]^1];++i)
			f1[1][i]=1;
	}
	else
		f1[1][nex[0][b[1]]]=1;
	for(int i=2;i<=m;++i){
		for(int j=1;j<=n;++j){
			if(f1[i-1][j]){
				if(a[j+1]==b[i]){
					++f1[i][j+1];
					if(nex[j][b[i]^1])--f1[i][nex[j][b[i]^1]];
				}
				else{
					if(nex[j][b[i]])++f1[i][nex[j][b[i]]],--f1[i][nex[j][b[i]]+1];
				}
				las1[i-1][j]=j;
			}
			else
				las1[i-1][j]=las1[i-1][j-1];
		}
		for(int j=1;j<=n;++j)
			f1[i][j]+=f1[i][j-1];
	}
	for(int i=n;i>=1;--i){
		if(f1[m][i]&&(nex[i][0]==0||nex[i][1]==0)){
			puts("YES");
			solve1(m,i);
			return;
		}
	}
	puts("NO");
}
int f[2010][2010],las[2010][2010];
void solve(int i,int j){
	if(i==1){
		printf("%d ",j);
		return;
	}
	solve(i-1,las[i-1][j-1]);
	printf("%d ",j);
}
int main(){
	scanf("%s%s",a+1,b+1);
	n=strlen(a+1),m=strlen(b+1);
	for(int i=1;i<=n;++i)a[i]-='A';
	for(int i=1;i<=m;++i)b[i]-='A';
	for(int i=n-1;i>=0;--i){
		nex[i][a[i+1]]=i+1;
		nex[i][a[i+1]^1]=nex[i+1][a[i+1]^1];
	}
	if(m<=20){
		deal1();
		return 0;
	}
	if(a[1]==b[1]){
		for(int i=1;i<nex[1][a[1]^1]==0?n+1:nex[1][a[1]^1];++i)
			f[1][i]=1;
	}
	else
		f[1][nex[0][b[1]]]=1;
	for(int i=2;i<=m;++i){
		for(int j=1;j<=n;++j){
			if(f[i-1][j]){
				if(a[j+1]==b[i]){
					++f[i][j+1];
					if(nex[j][b[i]^1])--f[i][nex[j][b[i]^1]];
				}
				else{
					if(nex[j][b[i]])++f[i][nex[j][b[i]]],--f[i][nex[j][b[i]]+1];
				}
				las[i-1][j]=j;
			}
			else
				las[i-1][j]=las[i-1][j-1];
		}
		for(int j=1;j<=n;++j)
			f[i][j]+=f[i][j-1];
	}
	for(int i=n;i>=1;--i){
		if(f[m][i]&&(nex[i][0]==0||nex[i][1]==0)){
			puts("YES");
			solve(m,i);
			return 0;
		}
	}
	puts("NO");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

BBAAABBAAABAAA
BAAB

output:


result: