結果

問題 No.465 PPPPPPPPPPPPPPPPAPPPPPPPP
ユーザー vjudge1
提出日時 2025-07-29 10:36:56
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 949 bytes
コンパイル時間 4,474 ms
コンパイル使用メモリ 169,172 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-07-29 10:37:03
合計ジャッジ時間 6,640 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 4 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5e3 + 5;
const int mod = 998244353, B = 233;
int n, f[N], g[N], base[N];
char c[N];
bool check(int l, int r) {
	int cnt1 = (f[r] - f[l - 1] * base[r - l + 1] % mod + mod) % mod;
	int cnt2 = (g[l] - g[r + 1] * base[r - l + 1] % mod + mod) % mod;
	return cnt1 == cnt2;
}
int sum[N], ans;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> (c + 1);
	n = strlen(c + 1);
	base[0] = 1;
	for (int i = 1; i <= n; i++) {
		base[i] = base[i - 1] * B % mod;
		f[i] = (f[i - 1] * B + c[i] - 'a') % mod;
	}	
	for (int i = n; i >= 1; i--) {
		g[i] = (g[i + 1] * B + c[i] - 'a') % mod;
	}
	for (int i = n; i >= 1; i--) {
		sum[i] = check(i, n) + sum[i + 1];
	}
	for (int i = 1; i <= n - 2; i++) {
		if(!check(1, i)) continue;
		for (int j = i + 1; j <= n - 2; j++) {
			if(check(i + 1, j)) {
				ans += sum[j + 2];
			}
		}
	}
	cout << ans;
	return 0;
}
0