結果

問題 No.464 PPAP
ユーザー ei1333333ei1333333
提出日時 2018-11-22 00:45:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 309 ms / 2,000 ms
コード長 643 bytes
コンパイル時間 2,428 ms
コンパイル使用メモリ 199,232 KB
実行使用メモリ 101,388 KB
最終ジャッジ日時 2023-08-26 02:43:59
合計ジャッジ時間 6,723 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
101,028 KB
testcase_01 AC 37 ms
101,084 KB
testcase_02 AC 37 ms
101,040 KB
testcase_03 AC 38 ms
101,032 KB
testcase_04 AC 37 ms
101,200 KB
testcase_05 AC 38 ms
101,092 KB
testcase_06 AC 37 ms
101,096 KB
testcase_07 AC 46 ms
101,076 KB
testcase_08 AC 47 ms
101,120 KB
testcase_09 AC 44 ms
101,360 KB
testcase_10 AC 289 ms
101,388 KB
testcase_11 AC 132 ms
101,184 KB
testcase_12 AC 290 ms
101,252 KB
testcase_13 AC 159 ms
101,228 KB
testcase_14 AC 286 ms
101,224 KB
testcase_15 AC 29 ms
101,040 KB
testcase_16 AC 28 ms
101,036 KB
testcase_17 AC 28 ms
101,156 KB
testcase_18 AC 28 ms
101,092 KB
testcase_19 AC 28 ms
101,092 KB
testcase_20 AC 28 ms
101,044 KB
testcase_21 AC 28 ms
101,088 KB
testcase_22 AC 28 ms
101,048 KB
testcase_23 AC 169 ms
101,308 KB
testcase_24 AC 286 ms
101,356 KB
testcase_25 AC 309 ms
101,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;


string S;
int g[5000][5000];
int64 dp[5][5001];

bool is_palindrome(int l, int r) {
  if(~g[l][r]) return g[l][r];
  if(l >= r) return true;
  if(S[l] != S[r]) return false;
  return g[l][r] = is_palindrome(l + 1, r - 1);
}

int main() {
  cin >> S;
  memset(g, -1, sizeof(g));
  int N = (int) S.size();
  dp[0][0] = 1;
  for(int i = 1; i <= 4; i++) {
    for(int j = 0; j < N; j++) {
      for(int k = j + 1; k <= N; k++) {
        if(i == 3 || is_palindrome(j, k - 1)) {
          dp[i][k] += dp[i - 1][j];
        }
      }
    }
  }
  cout << dp[4][N] << endl;
}

0