結果

問題 No.464 PPAP
ユーザー goodbatongoodbaton
提出日時 2019-02-19 22:43:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 2,151 bytes
コンパイル時間 948 ms
コンパイル使用メモリ 101,360 KB
実行使用メモリ 73,088 KB
最終ジャッジ日時 2024-04-21 00:47:37
合計ジャッジ時間 2,515 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,448 KB
testcase_01 AC 5 ms
8,448 KB
testcase_02 AC 5 ms
8,576 KB
testcase_03 AC 4 ms
8,448 KB
testcase_04 AC 5 ms
8,448 KB
testcase_05 AC 5 ms
8,448 KB
testcase_06 AC 4 ms
8,448 KB
testcase_07 AC 10 ms
11,136 KB
testcase_08 AC 9 ms
10,368 KB
testcase_09 AC 5 ms
8,576 KB
testcase_10 AC 208 ms
73,088 KB
testcase_11 AC 27 ms
19,200 KB
testcase_12 AC 44 ms
27,264 KB
testcase_13 AC 6 ms
8,832 KB
testcase_14 AC 119 ms
50,432 KB
testcase_15 AC 5 ms
8,320 KB
testcase_16 AC 5 ms
8,448 KB
testcase_17 AC 4 ms
8,448 KB
testcase_18 AC 5 ms
8,448 KB
testcase_19 AC 4 ms
8,448 KB
testcase_20 AC 5 ms
8,576 KB
testcase_21 AC 5 ms
8,448 KB
testcase_22 AC 4 ms
8,448 KB
testcase_23 AC 5 ms
8,832 KB
testcase_24 AC 5 ms
8,832 KB
testcase_25 AC 6 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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さんブログ) */

// R[i] := 文字 i を中心とする最長の回文の半径( 全長+1 / 2 )
// 偶数長は文字間にダミーを入れる(例: a#b#a#c#b)
void Manacher(const char *S, int *R){
  int i = 0, j = 0, k, n = strlen(S);
  while (S[i]) {
    while (i-j >= 0 && i+j < n && S[i-j] == S[i+j]) j++;
    R[i] = j;
    for (k = 1; i-k >= 0 && i+k < n && 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 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] = '#';

  int pal[SIZE];

  Manacher(t, pal);

  for(int i=0;i<n;i++)
    for(int j=0;j<pal[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<pal[i*2+2]/2;j++)
      vec[i-j].push_back(i+j+1);

  dp[0][0] = 1;

  ll sum = 0;

  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];
  }

  cout << dp[4][n] << endl;

  return 0;
}
0