結果

問題 No.464 PPAP
ユーザー square1001
提出日時 2017-03-08 12:56:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 640 bytes
コンパイル時間 546 ms
コンパイル使用メモリ 66,340 KB
実行使用メモリ 27,644 KB
最終ジャッジ日時 2024-06-23 18:52:42
合計ジャッジ時間 2,693 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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