QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#245951#4669. Genetic ModificationsQZJ123456TL 1ms7800kbC++141.7kb2023-11-10 14:46:572023-11-10 14:46:59

Judging History

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

  • [2023-11-10 14:46:59]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7800kb
  • [2023-11-10 14:46:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
char s[100005],t[100005];
int pos1[2005][2005],n,m,lst[2];
vector<int>vec,out;
int pos2[100005][25];
void solve1(){
	for(int i=1;i<=m;i++)pos1[0][i]=-1e9;
	pos1[0][0]=0;
	for(int i=1;i<=n;i++){
		int p=lst[(s[i-1]-'0')^1];
		vec.clear();
		for(int j=0;j<m;j++){
			if(s[i]==t[j+1]&&pos1[i-1][j]>=p)vec.push_back(j+1);
		}
		for(int j=0;j<=m;j++)pos1[i][j]=pos1[i-1][j];
		for(auto to:vec)pos1[i][to]=i;
		lst[s[i]-'0']=i;
	}
	if(pos1[n][m]<0){
		puts("NO");
		exit(0);
	}
	for(int i=pos1[n][m]+1;i<=n;i++){
		if(s[i]!=s[n]){
			puts("NO");
			exit(0);
		}
	}
	puts("YES");
	int now=n;
	for(int i=m;i;i--){
		out.push_back(pos1[now][i]);
		now=pos1[now][i];
	}
	reverse(out.begin(),out.end());
	for(auto to:out)printf("%d ",to);
}
void solve2(){
	for(int i=1;i<=m;i++)pos2[0][i]=-1e9;
	pos2[0][0]=0;
	for(int i=1;i<=n;i++){
		int p=lst[(s[i-1]-'0')^1];
		vec.clear();
		for(int j=0;j<m;j++){
			if(s[i]==t[j+1]&&pos2[i-1][j]>=p)vec.push_back(j+1);
		}
		for(int j=0;j<=m;j++)pos2[i][j]=pos2[i-1][j];
		for(auto to:vec)pos2[i][to]=i;
		lst[s[i]-'0']=i;
	}
	if(pos2[n][m]<0){
		puts("NO");
		exit(0);
	}
	for(int i=pos2[n][m]+1;i<=n;i++){
		if(s[i]!=s[n]){
			puts("NO");
			exit(0);
		}
	}
	puts("YES");
	int now=n;
	for(int i=m;i;i--){
		out.push_back(pos2[now][i]);
		now=pos2[now][i];
	}
	reverse(out.begin(),out.end());
	for(auto to:out)printf("%d ",to);
}
int main(){
	scanf("%s",s+1);scanf("%s",t+1);
	n=strlen(s+1),m=strlen(t+1);
	for(int i=1;i<=n;i++)if(s[i]=='A')s[i]='0';else s[i]='1';
	for(int i=1;i<=m;i++)if(t[i]=='A')t[i]='0';else t[i]='1';
	if(n<=2000)solve1();
	else solve2();
	return 0;
}

详细

Test #1:

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

input:

BBAAABBAAABAAA
BAAB

output:

YES
2 5 8 11 

result:

ok good solution

Test #2:

score: 0
Accepted
time: 0ms
memory: 7800kb

input:

ABABABABAB
ABAB

output:

NO

result:

ok no solution

Test #3:

score: -100
Time Limit Exceeded

input:

BBAAAAABBAAAAAABBABAABBBBBAABBBAAABABBABABBBAAABBAAAABBBBBABAABBBAABBBBBBBABBABABBAAAABBAAAABAAAABBABAAAAAAABBBBAAAAAABAABABBAAAAABBBBAABABABAAAAABBBABABBAABABBBBAABAABBBBBABBABABBAAABBAAAABBBABBABAAAABBBAABAAABBBAAAAAAAAAAAAABABBAABBBBABABAABBBBABAABBAAABABBBBAAAAAAAABBAAAABBABABABBBAAABAABBABBAAAA...

output:


result: