結果

問題 No.465 PPPPPPPPPPPPPPPPAPPPPPPPP
ユーザー 👑 kmjpkmjp
提出日時 2016-12-16 03:09:16
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,470 bytes
コンパイル時間 2,761 ms
コンパイル使用メモリ 171,684 KB
実行使用メモリ 58,924 KB
最終ジャッジ日時 2024-05-07 15:53:45
合計ジャッジ時間 5,290 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
14,600 KB
testcase_01 AC 2 ms
7,524 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
7,652 KB
testcase_04 AC 3 ms
7,400 KB
testcase_05 AC 10 ms
12,140 KB
testcase_06 AC 43 ms
40,896 KB
testcase_07 AC 10 ms
14,184 KB
testcase_08 AC 35 ms
39,748 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
32_ratsliveonnoevilstar.txt -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

struct PalindromicTree {
	struct node {
		map<char,int> next;
		int len, sufflink,num,first;
	};
	string S;
	vector<node> V;
	int n,s; // num,suff
	
	bool add(int pos) {
		char ch=S[pos];
		int c=s, cl=0;
		while(1) {
			cl=V[c].len;
			if(pos-1-cl>=0 && S[pos-1-cl]==ch) break;
			c=V[c].sufflink;
		}
		
		if(V[c].next.count(ch)) {
			s = V[c].next[ch];
			return false;
		}
		
		s=++n;
		V[n].len=V[c].len+2;
		V[n].first=pos;
		V[c].next[ch]=n;
		
		if(V[n].len==1) { // even length
			V[n].sufflink=2;
			V[n].num=1;
			return true;
		}
		
		while(1) {
			c=V[c].sufflink;
			cl=V[c].len;
			if(pos-1-cl>=0 && S[pos-1-cl]==ch) {
				V[n].sufflink=V[c].next[ch];
				break;
			}
		}
		V[n].num=1+V[V[n].sufflink].num;
		return true;
	}
	
	void init(string S) {
		this->S=S;
		V.clear();
		V.resize(S.size()+10);
		
		n=s=2;
		V[1].first=V[2].first=-1;
		V[1].len=-1;
		V[2].len=0;
		V[1].sufflink=V[2].sufflink=1;
	}
};

int L;
string S;
int pnode[505050];
int pre[505050],post[505050];

void solve() {
	int i,j,k,l,r,x,y; string s;
	cin>>S;
	L=S.size();
	
	PalindromicTree pt;
	pt.init(S);
	FOR(i,L) {
		pt.add(i);
		pnode[i]=pt.s;
		if(pt.V[pt.s].len==i+1) pre[i]=1;
	}
	x=pnode[L-1];
	while(x>=3) {
		post[L-pt.V[x].len]=1;
		x=pt.V[x].sufflink;
	}
	for(i=L;i>=0;i--) post[i]+=post[i+1];
	
	ll ret=0;
	for(i=2;i<=L-2;i++) {
		x=pnode[i-1];
		while(x>=3) {
			if(pt.V[x].len<i && pre[i-pt.V[x].len-1]) ret+=post[i+1];
			x=pt.V[x].sufflink;
		}
	}
	cout<<ret<<endl;
	
	/*
	
	FOR(i,L) par[i][i+1]=1;
	FOR(i,L-1) if(S[i]==S[i+1]) par[i][i+2]=1;
	for(i=3;i<=L;i++) {
		for(x=0;x+i<=L;x++) if(par[x+1][x+i-1] && S[x]==S[x+i-1]) par[x][x+i]=1;
	}
	ll ret=0;
	for(i=2;i<=L;i++) {
		y=0;
		for(x=1;x<i;x++) if(par[0][x] && par[x][i]) y++;
		for(x=1;i+x<L;x++) if(par[L-x][L]) ret+=y;
	}
	cout<<ret<<endl;
	*/
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0