QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#361140#5440. P-P-PalindromeqwqUwU_Compile Error//C++142.2kb2024-03-22 20:29:322024-03-22 20:29:33

Judging History

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

  • [2024-03-22 20:29:33]
  • 评测
  • [2024-03-22 20:29:32]
  • 提交

answer

// clang-format off
#include<bits/stdc++.h>
#define pb push_back
#define p make_pair
#define st first
#define nd second
#define bit(s,x) (((s)>>(x))&1)
#define ctz(s) __builtin_popcount(s)
using namespace std;
typedef long long ll; 
typedef unsigned long long ull; 
//typedef __int128 i128; 
typedef long double ld;
typedef pair<int,int> pii; typedef pair<ll,int> pli; typedef pair<ll,ll> pll; typedef pair<int,ll> pil;
inline ll read(){
	ll x=0,f=1,c=getchar();
	while(c<'0'||c>'9')f=(c=='-'?-1:1),c=getchar();
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
inline void write(ll x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); }
// remember to change!!!
const int mod=998244353;
inline void plust(int &x,int y,int p=mod){x=x+y<p?x+y:x+y-p;}
inline void mul(int &x,int y,int p=mod){x=1ll*x*y%p;}
inline int fp(int x,ll p=mod-2,int m=mod,int res=1){
	for(;p;p>>=1){if(p&1)mul(res,x,m);mul(x,x,m);}
	return res;
}
const int n=1e6+3;
const int inf=0x3fffffff;
// clang-format on
int n;
string str[n];
int fa[n],tot=1,lst,cur,nxt[n][26],len[n];
inline void init(){
	lst=0,cur=-1;
	len[0]=0,len[1]=-1;
	fa[0]=1,fa[1]=0;
}
inline int getfail(int i,int x){
	for(;cur-len[x]-1 <0 || str[i][cur-len[x]-1] != str[i][cur];x=fa[x]);
	return x;
}
inline void insert(int i,int c){
	++cur;int p=getfail(i,lst);
	if(!nxt[p][c]){
		int x = ++tot;len[x] = len[p] + 2;
		fa[x] = nxt[getfail(i,fa[p])][c];
		nxt[p][c]=x;
	}
	lst=nxt[p][c];
}
vector<int>g[n];
int vis[n];
vector<int>vec[n];
int t2[n];
inline void dfs(int u){
	vis[len[u]]=u;
	for(auto x:vec[len[u]])if(vis[len[u]-x]){++t2[vis[x]];break;}
	for(auto v:g[u])dfs(v);
	vis[len[u]]=0;
}
int main() {
    //freopen("data.in", "r", stdin);
    // freopen(".in","r",stdin);
    // freopen("myans.out","w",stdout);
	n=read();
	for(int i=1;i<=n;++i)cin>>str[i];
	for(int i=1;i<=n;++i){
		init();
		for(int j=0;j<str[i].length();++j){
			insert(i,str[i][j]-'a');
		}
	}
	for(int i=2;i<=tot;++i)g[fa[i]?fa[i]:1].pb(i);
	for(int i=1;i<n;++i) for(int j=i;j<n;j+=i)vec[j].pb(i);
	vis[0]=1;for(auto u:g[1])dfs(u);
	ll ans=0;
	for(int i=2;i<=tot;++i)ans += 1ll*t2[i]*t2[i];
	cout<<ans;
    return 0;
}

Details

answer.code:33:5: error: conflicting declaration ‘int n’
   33 | int n;
      |     ^
answer.code:30:11: note: previous declaration as ‘const int n’
   30 | const int n=1e6+3;
      |           ^
answer.code: In function ‘int main()’:
answer.code:68:10: error: assignment of read-only variable ‘n’
   68 |         n=read();
      |         ~^~~~~~~