結果

問題 No.464 PPAP
ユーザー square1001square1001
提出日時 2017-03-08 12:56:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 640 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 64,432 KB
実行使用メモリ 27,704 KB
最終ジャッジ日時 2023-09-05 23:40:25
合計ジャッジ時間 2,414 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 6 ms
9,668 KB
testcase_08 AC 6 ms
9,544 KB
testcase_09 AC 5 ms
9,356 KB
testcase_10 AC 80 ms
27,472 KB
testcase_11 AC 38 ms
23,832 KB
testcase_12 AC 62 ms
27,496 KB
testcase_13 AC 55 ms
27,704 KB
testcase_14 AC 61 ms
27,528 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 56 ms
27,084 KB
testcase_24 AC 58 ms
27,092 KB
testcase_25 AC 57 ms
27,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <iostream>
using namespace std;
string s; int cnt[5005]; bool dp[5005][5005];
int main() {
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i++) dp[i][i] = dp[i][i + 1] = true;
	for (int i = 2; i <= n; i++) {
		for (int l = 0; l <= n - i; l++) {
			int r = l + i;
			if (dp[l + 1][r - 1] && s[l] == s[r - 1]) dp[l][r] = true;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (dp[0][i] && dp[i][j]) cnt[j]++;
		}
	}
	long long ret = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (dp[j][n]) ret += cnt[i];
		}
	}
	cout << ret << endl;
	return 0;
}
0