結果
| 問題 |
No.464 PPAP
|
| コンテスト | |
| ユーザー |
goodbaton
|
| 提出日時 | 2019-02-20 00:24:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 196 ms / 2,000 ms |
| コード長 | 2,149 bytes |
| コンパイル時間 | 964 ms |
| コンパイル使用メモリ | 101,096 KB |
| 実行使用メモリ | 73,088 KB |
| 最終ジャッジ日時 | 2024-10-13 06:27:38 |
| 合計ジャッジ時間 | 2,262 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 22 |
ソースコード
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <cassert>
typedef long long ll;
using namespace std;
#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
out << "{" << p.first << ", " << p.second << "}";
return out;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
out << '{';
for (const T &item : v) out << item << ", ";
out << "\b\b}";
return out;
}
#endif
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010
/* Manacher.cpp (Source: snukeさんブログ) */
/* Manacher.cpp */
// R[i] := 文字 i を中心とする最長の回文の半径( 全長+1 / 2 )
// 偶数長は文字間にダミーを入れる(例: a#b#a#c#b)
void Manacher(const char *S, int *R){
int i = 0, j = 0, k;
while (S[i]) {
while (i-j >= 0 && S[i+j] && S[i-j] == S[i+j]) j++;
R[i] = j;
for (k = 1; i-k >= 0 && S[i+k] && k+R[i-k] < j; k++) R[i+k] = R[i-k];
i += k; j -= k;
}
}
char s[SIZE], t[SIZE];
vector<int> vec[SIZE];
ll dp[5][SIZE];
int pr[SIZE];
int main(){
int n;
scanf("%s", s);
n = strlen(s);
for(int i=0;i<n;i++) {
t[i*2] = '#';
t[i*2+1] = s[i];
}
t[n*2] = '#';
Manacher(t, pr);
for(int i=0;i<n;i++)
for(int j=0;j<pr[i*2+1]/2;j++)
vec[i-j].push_back(i+j);
for(int i=0;i<n-1;i++)
for(int j=0;j<pr[i*2+2]/2;j++)
vec[i-j].push_back(i+j+1);
ll sum = 0;
dp[0][0] = 1;
for(int i=0;i<n;i++){
dp[3][i] += sum;
for(int to : vec[i]) {
dp[1][to+1] += dp[0][i];
dp[2][to+1] += dp[1][i];
dp[4][to+1] += dp[3][i];
}
sum += dp[2][i];
}
printf("%lld\n", dp[4][n]);
return 0;
}
goodbaton