結果

問題 No.464 PPAP
ユーザー hotpepsihotpepsi
提出日時 2016-12-23 01:08:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 1,362 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 64,432 KB
実行使用メモリ 52,496 KB
最終ジャッジ日時 2023-08-21 05:48:17
合計ジャッジ時間 2,408 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
52,180 KB
testcase_01 AC 15 ms
52,288 KB
testcase_02 AC 15 ms
52,220 KB
testcase_03 AC 15 ms
52,240 KB
testcase_04 AC 15 ms
52,192 KB
testcase_05 AC 14 ms
52,212 KB
testcase_06 AC 16 ms
52,244 KB
testcase_07 AC 18 ms
52,188 KB
testcase_08 AC 16 ms
52,180 KB
testcase_09 AC 14 ms
52,188 KB
testcase_10 AC 232 ms
52,280 KB
testcase_11 AC 29 ms
52,260 KB
testcase_12 AC 37 ms
52,496 KB
testcase_13 AC 16 ms
52,480 KB
testcase_14 AC 125 ms
52,248 KB
testcase_15 AC 15 ms
52,184 KB
testcase_16 AC 15 ms
52,212 KB
testcase_17 AC 14 ms
52,264 KB
testcase_18 AC 14 ms
52,304 KB
testcase_19 AC 14 ms
52,304 KB
testcase_20 AC 14 ms
52,216 KB
testcase_21 AC 15 ms
52,180 KB
testcase_22 AC 14 ms
52,216 KB
testcase_23 AC 15 ms
52,240 KB
testcase_24 AC 14 ms
52,308 KB
testcase_25 AC 14 ms
52,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <cstring>

using namespace std;
typedef long long LL;

int main(int argc, char *argv[]) {
	string s;
	cin >> s;
//	set<int> p[5001], r[5001];
	char p[5001][5001] = {}, r[5001][5001] = {};
	int len = (int)s.length();
	for (int i = 0; i < len; ++i) {
		for (int j = 0; (i - j) >= 0 && (i + j) < len; ++j) {
			if (s[i - j] == s[i + j]) {
//				p[i - j].insert(j * 2 + 1);
//				r[i + j + 1].insert(j * 2 + 1);
				p[i - j][j * 2 + 1] = 1;
				r[i + j + 1][j * 2 + 1] = 1;
			} else {
				break;
			}
		}
		for (int j = 0; (i - j) >= 0 && (i + j + 1) < len; ++j) {
			if (s[i - j] == s[i + j + 1]) {
//				p[i - j].insert(j * 2 + 2);
//				r[i + j + 2].insert(j * 2 + 2);
				p[i - j][j * 2 + 2] = 1;
				r[i + j + 2][j * 2 + 2] = 1;
			} else {
				break;
			}
		}
	}
	int cnt = 0;
	int right[5000] = {};
	for (int i = len - 1; i >= 0; --i) {
		right[i] = cnt;
//		if (r[len].find(len - i) != r[len].end()) {
		if (r[len][len - i]) {
			++cnt;
		}
	}
	LL ans = 0;
	int left[5000] = {};
//	for (int i : p[0]) {
//		for (int j : p[a]) {
	for (int i = 1; i < len; ++i) {
		if (p[0][i]) {
			for (int j = 1; j < len; ++j) {
				if (p[i][j]) {
					left[i + j] += 1;
				}
			}
		}
	}
	for (int i = 0; i < len; ++i) {
		ans += left[i] * right[i];
	}
	cout << ans << endl;
	return 0;
}
0