QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#480890#801. 回文自动机lmeowdn#0 2ms12072kbC++141.9kb2024-07-16 19:26:082024-07-16 19:26:08

Judging History

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

  • [2024-07-16 19:26:08]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:12072kb
  • [2024-07-16 19:26:08]
  • 提交

answer

//Shirasu Azusa 2024.7
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;  
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar();
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} 
  return x*w;
}

const int N=2e6+5;
int n,ans;
char s[N];

namespace PAM {
  int n,ch[N][25],nxt[N],len[N],tot=1,a[N],now=1,cnt[N];
  void init() {
    nxt[0]=1, len[1]=-1; now=1;
  }
  int get(int u,int i) {
    while(s[i-len[u]-1]!=s[i]) u=nxt[u];
    return u;
  }
  int newn(int l) {
    ++tot; len[tot]=l; return tot;
  }
  void extend(int x) {
    a[++n]=x; now=get(now,n);
    if(!ch[now][x]) {
      ch[now][x]=newn(len[now]+2);
      nxt[ch[now][x]]=get(nxt[now],n);
    } now=ch[now][x];
    cnt[now]++;
  }
  void solve() {
    per(i,tot,1) cnt[nxt[i]]+=cnt[i];
    rep(i,2,tot) chmax(ans,len[i]*len[i]*cnt[i]);
  }
}

signed main() {
  PAM::init(); scanf("%s",s+1); n=strlen(s+1);
  rep(i,1,n) PAM::extend(s[i]-'a'+1);
  PAM::solve();
  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: 2ms
memory: 12072kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

4772

result:

wrong answer expected '5594', found '4772'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%