QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#252603#801. 回文自动机Mobius_1270 34ms207788kbC++142.7kb2023-11-15 22:18:452023-11-15 22:18:46

Judging History

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

  • [2023-11-15 22:18:46]
  • 评测
  • 测评结果:0
  • 用时:34ms
  • 内存:207788kb
  • [2023-11-15 22:18:45]
  • 提交

answer


#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <cctype>
#include <vector>
#include <queue>
#include <bitset>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
typedef long long ll;
typedef pair <int, int> Pii;
const int INF=0x3f3f3f3f;
const int cp=998244353;
inline int mod(int x){if(x>=cp) x-=cp;if(x<0) x+=cp;return x;}
inline void plust(int &x, int y){x=mod(x+y);return ;}
inline void minut(int &x, int y){x=mod(x-y);return ;}
inline int read(){
	char ch=getchar();int x=0, f=1;
	while(!isdigit(ch)){if(ch=='-') f=-1; ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
inline void write(int x){
    if(x<0) putchar('-'), x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline int ksm(int a, int b=cp-2){
	int ret=1;
	for(; b; b>>=1, a=1ll*a*a%cp)
		if(b&1) ret=1ll*ret*a%cp;
	return ret;
}
const int N=4e6+6;
const int Nc=N+N;
const int Mc=N+N+N;
namespace SAM{
	int ndc, lst, siz[Nc];
	struct node{int fa, nxt[26], len;}sam[Nc];
	int clr(int x){sam[x]=sam[0], siz[x]=0;return x;}
	void init(){clr(ndc=lst=1);}
	int insert(char c){
		int cur=clr(++ndc), p=lst, cc=c-'a';sam[cur].len=sam[p].len+1;
		for(; p&&!sam[p].nxt[cc]; p=sam[p].fa) sam[p].nxt[cc]=cur;
		int q=sam[p].nxt[cc];
		if(!q) sam[cur].fa=1;
		else if(sam[q].len==sam[p].len+1) sam[cur].fa=q;
		else{
			int nex=clr(++ndc);sam[nex]=sam[q];sam[nex].len=sam[p].len+1;
			for(; p&&sam[p].len==q; p=sam[p].fa) sam[p].nxt[cc]=nex;
			sam[cur].fa=sam[q].fa=nex;
		}
		return lst=cur;
	}
	int pos[N];
	void insert_str(int n, char *s){init();for(int i=1; i<=n; ++i) pos[i]=insert(s[i]), siz[pos[i]]=1;}
	vi G[Nc];int fa[Nc][25];
	void dfs(int x){
		for(int i=1; i<25; ++i) fa[x][i]=fa[fa[x][i-1]][i-1];
		for(auto v:G[x]) fa[v][0]=x, dfs(v), siz[x]+=siz[v];
	}
	void pre(){for(int i=2; i<=ndc; ++i) G[sam[i].fa].pb(i);dfs(1);}
	int Ocnum(int l, int r){
		int x=pos[r];
		for(int i=24; i>=0; --i) if(sam[fa[x][i]].len>=r-l+1) x=fa[x][i];
		return siz[x];
	}
}
int n, p[Nc];char s[N], t[Nc];ll ans;
ll calc(int x, int y){
	if(t[x]=='#'&&t[y]=='#') x=x+1>>1, y=y-1>>1;
	else x>>=1, y>>=1;
	return 1ll*(y-x+1)*(y-x+1)*SAM :: Ocnum(x, y);
}
signed main(){
	scanf("%s", s+1);n=strlen(s+1);SAM :: insert_str(n, s);SAM :: pre();
	t[0]='~';t[1]='#';
	for(int i=1; i<=n; ++i) t[i+i]=s[i], t[i+i+1]='#';
	// printf("%s\n", t+1);
	for(int i=1, R=0, mid=0; i<=n+n+1; ++i){
		if(i<R) p[i]=min(R-i, p[mid*2-i]);
		while(t[i-p[i]-1]==t[i+p[i]+1]) ++p[i], ans=max(ans, calc(i-p[i], i+p[i]));
		if(i+p[i]>R) R=i+p[i], mid=i;
	}
	printf("%lld\n", ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 34ms
memory: 207788kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

26280

result:

wrong answer expected '5594', found '26280'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%