結果

問題 No.464 PPAP
ユーザー fumofumofunifumofumofuni
提出日時 2022-09-06 23:32:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 2,232 bytes
コンパイル時間 2,175 ms
コンパイル使用メモリ 206,668 KB
実行使用メモリ 199,312 KB
最終ジャッジ日時 2023-08-14 05:13:25
合計ジャッジ時間 5,591 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 13 ms
11,300 KB
testcase_08 AC 12 ms
11,364 KB
testcase_09 AC 10 ms
11,276 KB
testcase_10 AC 362 ms
199,280 KB
testcase_11 AC 139 ms
129,056 KB
testcase_12 AC 217 ms
199,272 KB
testcase_13 AC 190 ms
199,308 KB
testcase_14 AC 279 ms
199,304 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 187 ms
199,300 KB
testcase_24 AC 189 ms
199,292 KB
testcase_25 AC 189 ms
199,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")


#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,1,0,-1,1,-1,1,-1,0};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}

vector< int > manacher(const string &s) {
  vector< int > radius(s.size());
  int i = 0, j = 0;
  while(i < s.size()) {
    while(i - j >= 0 && i + j < s.size() && s[i - j] == s[i + j]) {
      ++j;
    }
    radius[i] = j;
    int k = 1;
    while(i - k >= 0 && i + k < s.size() && k + radius[i - k] < j) {
      radius[i + k] = radius[i - k];
      ++k;
    }
    i += k;
    j -= k;
  }
  return radius;
}

int main(){
  string s;cin >> s;
  string t;
  rep(i,s.size()){
    t+=s[i];t+="$";
  }
  t.pop_back();
  ll n=s.size();
  vvl pal(n,vl(n+1));
  auto f=manacher(s);
  rep(i,n){
    ll left=i,right=i+1;
    rep(_,f[i]){
      pal[left][right]++;
      left--;right++;
    }
  }
  auto g=manacher(t);
  rep(i,n-1){
    ll left=i,right=i+2;
    rep(_,g[i*2+1]/2){
      pal[left][right]++;
      left--;right++;
    }
  }
  /*rep(i,n){
    rep(j,n+1)cout << pal[i][j] <<" ";cout << endl;
  }*/
  vvl dp(n+1,vl(4));
  rep(i,n+1)dp[i][0]=pal[0][i];
  rep(i,n){
    rep(j,3){
      for(ll k=i+1;k<=n;k++){
        if(j==0||j==2){
          if(pal[i][k])dp[k][j+1]+=dp[i][j];
        }
        else {
          dp[k][j+1]+=dp[i][j];
        }
      }
    }
  }
  /*rep(i,n){
    rep(j,4)cout << dp[i][j] <<" ";cout << endl;
  }*/
  cout << dp[n][3] << endl;
}
0