QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#717937#8521. Pattern Search IIyhdddWA 19ms167980kbC++141.8kb2024-11-06 19:19:152024-11-06 19:19:18

Judging History

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

  • [2024-11-06 19:19:18]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:167980kb
  • [2024-11-06 19:19:15]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=150010;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n,m=6,ans=inf;
char s[maxn];
struct nd{
	int len;
	pii pre[maxn],suf[maxn];
}f[32];
nd merge(nd u,nd v){
	nd res;res.len=u.len+v.len;
	for(int i=1;i<=n;i++){
		res.suf[i]=u.suf[i].fi==n+1?u.suf[i]:make_pair(v.suf[u.suf[i].fi].fi,u.len+v.suf[u.suf[i].fi].se);
		res.pre[i]=v.pre[i].fi==0?v.pre[i]:make_pair(u.pre[v.pre[i].fi].fi,v.len+u.pre[v.pre[i].fi].se);
		if(u.pre[i].fi==0&&v.suf[i+1].fi==n+1)ans=min(ans,u.pre[i].se+v.suf[i+1].se);
	}
	return res;
}
void work(){
	scanf("%s",s+1);n=strlen(s+1);
	if(n==1){puts("1");return ;}
	for(int i=1;i<=n;i++){
		if(s[i]=='a'){
			f[1].pre[i]={i-1,1},f[1].suf[i]={i+1,1};
			f[0].pre[i]=f[0].suf[i]={i,0};
		}
		else{
			f[0].pre[i]={i-1,1},f[0].suf[i]={i+1,1};
			f[1].pre[i]=f[1].suf[i]={i,0};
		}
	}
	f[0].len=f[1].len=1;
	for(int i=2;i<=m;i++)f[i]=merge(f[i-1],f[i-2]);
	// for(int j=2;j<=m;j++){
		// cout<<j<<" "<<f[j].len<<"\n";
		// for(int i=1;i<=n;i++)cout<<f[j].pre[i].fi<<" "<<f[j].pre[i].se<<" "<<f[j].suf[i].fi<<" "<<f[j].suf[i].se<<"\n";
	// }
	printf("%lld\n",ans);
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=1;
	while(T--)work();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 12ms
memory: 167980kb

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 3ms
memory: 158460kb

input:

a

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 8ms
memory: 158416kb

input:

b

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

aa

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 16ms
memory: 167976kb

input:

bb

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 0
Accepted
time: 14ms
memory: 167980kb

input:

ab

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 18ms
memory: 167876kb

input:

ba

output:

2

result:

ok 1 number(s): "2"

Test #8:

score: 0
Accepted
time: 11ms
memory: 167952kb

input:

bbba

output:

7

result:

ok 1 number(s): "7"

Test #9:

score: -100
Wrong Answer
time: 12ms
memory: 167980kb

input:

abbbbbbbab

output:

1000000000000000000

result:

wrong answer 1st numbers differ - expected: '20', found: '1000000000000000000'