QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#331761#7955. Tandem Copylzy2005WA 1ms3924kbC++145.5kb2024-02-18 19:00:522024-02-18 19:00:52

Judging History

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

  • [2024-02-18 19:00:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3924kb
  • [2024-02-18 19:00:52]
  • 提交

answer

#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(2)

#include<bits/stdc++.h>

typedef unsigned ui;
typedef long long lli;
typedef unsigned long long ull;

const int F=(1<<30)-1;
const lli FF=(1ll<<62)-1ll;

namespace Fast_IO{
	const int SZ=1<<20;
	char buf[SZ+5],*p1,*p2;
	char obuf[SZ+5],*p3=obuf;
	char sbuf[45];int len=-1;
	inline char Get_Char(){
		if(p1==p2){
			p1=buf,p2=p1+fread(buf,1,SZ,stdin);
			if(p1==p2)return EOF;
		}
		return *p1++;
	}
	inline void Put_Char(char c){
		if(p3-obuf==SZ){
			fwrite(obuf,p3-obuf,1,stdout);
			p3=obuf;
		}
		*p3++=c;
	}
	inline int Get_Int(){
		int x=0;bool sg=0;
		char c=Get_Char();
		while(!isdigit(c)&&c!='-')c=Get_Char();
		if(c=='-')sg=1,c=Get_Char();
		while(isdigit(c))x=x*10+c-'0',c=Get_Char();
		return sg?-x:x;
	}
	inline lli Get_Int64(){
		lli x=0;bool sg=0;
		char c=Get_Char();
		while(!isdigit(c)&&c!='-')c=Get_Char();
		if(c=='-')sg=1,c=Get_Char();
		while(isdigit(c))x=x*10+c-'0',c=Get_Char();
		return sg?-x:x;
	}
	inline __int128_t Get_Int128(){
		__int128_t x=0;bool sg=0;
		char c=Get_Char();
		while(!isdigit(c)&&c!='-')c=Get_Char();
		if(c=='-')sg=1,c=Get_Char();
		while(isdigit(c))x=x*10+c-'0',c=Get_Char();
		return sg?-x:x;
	}
	inline void Put_Int(int x){
		if(x<0)Put_Char('-'),x=-x;
		len=-1;
		do buf[++len]=x%10+48,x/=10;while(x);
		while(len>=0)Put_Char(buf[len--]);
		Put_Char('\n');
	}
	inline void Put_Int64(lli x){
		if(x<0)Put_Char('-'),x=-x;
		len=-1;
		do buf[++len]=x%10+48,x/=10;while(x);
		while(len>=0)Put_Char(buf[len--]);
		Put_Char('\n');
	}
	inline void Put_Int128(__int128_t x){
		if(x<0)Put_Char('-'),x=-x;
		len=-1;
		do buf[++len]=x%10+48,x/=10;while(x);
		while(len>=0)Put_Char(buf[len--]);
		Put_Char('\n');
	}
	inline void Flush(){
		fwrite(obuf,p3-obuf,1,stdout);
	}
}
using Fast_IO::Get_Int;
using Fast_IO::Get_Int64;
using Fast_IO::Get_Int128;
using Fast_IO::Put_Int;
using Fast_IO::Put_Int64;
using Fast_IO::Put_Int128;
using Fast_IO::Flush;

const int N=2e4,AB=26;

char s[N+5],t[N+5];
int n,m;

int nx[N+5][AB+5],pr[N+5][AB+5],nx2[N+5][AB+5][AB+5];

struct Data{
	int w,x;
}da[AB+5];

int fw[N+5];
int ans;

int main(){
	scanf("%s%s",s+1,t+1);
	n=strlen(s+1),m=strlen(t+1);

	std::fill(nx[m+1],nx[m+1]+AB,m+1);
	for(int i=m;i>=0;--i){
		std::copy(nx[i+1],nx[i+1]+AB,nx[i]);
		if(i)
			nx[i][t[i]-'A']=i;
		else
			for(int j=0;j<AB;++j)
				nx[i][j]=0;
	}

	std::fill(pr[0],pr[0]+AB,0);
	for(int i=1;i<=m+1;++i){
		std::copy(pr[i-1],pr[i-1]+AB,pr[i]);
		if(i!=m+1)
			pr[i][t[i]-'A']=i;
		else
			for(int j=0;j<AB;++j)
				pr[i][j]=m+1;
	}
	std::copy(pr[m+1],pr[m+1]+AB,pr[m+2]);

	for(int i=1;i<=m;++i){
		for(int j=0;j<AB;++j)
			da[j].w=j,da[j].x=nx[i][j];
		std::sort(da,da+AB,[](const Data&a,const Data&b){
			return a.x<b.x;
		});
		for(int j=0;j<AB;++j)
			for(int k=0;k<AB;++k){
				if(da[0].w!=j&&da[0].w!=k)
					nx2[i][j][k]=da[0].x;
				else if(da[1].w!=j&&da[1].w!=k)
					nx2[i][j][k]=da[1].x;
				else
					nx2[i][j][k]=da[2].x;
			}
	}

	for(int i=1;i<=n;++i){
		fw[i]=n+1;
		
		int l=0,r=nx2[1][s[i]-'A'][s[i]-'A']-1;
		if(r==m+1){
			fw[i]=i;
			continue;
		}

		for(int j=i+1;j<=n;++j){
			if(j!=i+1&&s[j]==s[j-2])
				l=nx[l][s[j]-'A'],r=pr[nx2[r+1][s[j]-'A'][s[j-1]-'A']][s[j]-'A'];
			else
				l=nx[r+1][s[j]-'A'],r=pr[nx2[r+1][s[j]-'A'][s[j-1]-'A']][s[j]-'A'];
			if(l>r)break;
			if(r==m+1){
				fw[i]=j;
				break;
			}
		}
	}

	for(int i=1;i<=n;++i)
		for(int j=i,mn=n+1;j<=n;++j){
			mn=std::min(mn,fw[j]);
			ans+=mn<=j;
		}
	
	printf("%d\n",ans);

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

ACGCG
CCG

output:

9

result:

ok single line: '9'

Test #2:

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

input:

TATCGC
TTCCG

output:

6

result:

ok single line: '6'

Test #3:

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

input:

ABCABC
ABC

output:

7

result:

ok single line: '7'

Test #4:

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

input:

ABCABC
ABCABC

output:

1

result:

ok single line: '1'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3924kb

input:

FUSBX
UUUUUUUUUU

output:

4

result:

wrong answer 1st lines differ - expected: '8', found: '4'