結果

問題 No.588 空白と回文
ユーザー h-izuh-izu
提出日時 2022-11-06 07:55:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 6,729 bytes
コンパイル時間 4,802 ms
コンパイル使用メモリ 277,820 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-19 23:06:42
合計ジャッジ時間 5,604 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef unsigned long long ull;
typedef long long ll;
const double PI = 3.14159265358979323846;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
// abab
// (true)
template <typename T>
bool chmax(T& a, const T& b) {
if (a < b) {
a = b; // ab
return true;
}
return false;
}
// abab
// (true)
template <typename T>
bool chmin(T& a, const T& b) {
if (a > b) {
a = b; // ab
return true;
}
return false;
}
// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
if (p == 0) return 1;
a %= mod;
if (p % 2 == 0) {
ll half = modpow(a, p / 2, mod) % mod;
return half * half % mod;
} else {
return a * modpow(a, p - 1, mod) % mod;
}
}
// a^p
ll powpow(ll a, ll p) {
if (p == 0) return 1;
if (p % 2 == 0) {
ll half = pow(a, p / 2);
return half * half;
} else {
return a * pow(a, p - 1);
}
}
// a/b
// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
ll moddiv(ll a, ll b, ll mod) { return a * modpow(b, mod - 2, mod); }
// nCa
ll modCombination(ll n, ll a, ll mod) {
if (n < 0 || a < 0 || n < a) return 0;
if (n - a < a) {
return modCombination(n, n - a, mod);
}
ll denominator = 1; //
ll numerator = 1; //
for (ll i = 0; i < a; i++) {
denominator *= a - i;
numerator *= n - i;
denominator %= mod;
numerator %= mod;
}
return numerator * modpow(denominator, mod - 2, mod) % mod;
}
vector<vector<ll>> combination(ll n) {
vector<vector<ll>> C(n + 1, vector<ll>(n + 1));
C[0][0] = 1;
rep(i, n) rep(j, i + 1) {
C[i + 1][j + 1] += C[i][j];
C[i + 1][j] += C[i][j];
}
return C;
}
// ref. https://drken1215.hatenablog.com/entry/2018/06/08/210000
class ModCombinationTable {
private:
ll mod;
vector<ll> fac, finv, inv;
public:
ModCombinationTable(ll n, ll _mod) : mod(_mod) {
fac.resize(n + 1);
finv.resize(n + 1);
inv.resize(n + 1);
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i <= n; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
ll operator()(ll n, ll k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
};
// cf. https://qiita.com/drken/items/a14e9af0ca2d857dad23
vector<ll> enum_divisors(ll n) {
vector<ll> res;
// sqrt(n)
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
// in/i
// e.g. n=25i=5
if (n / i != i) res.push_back(n / i);
}
}
sort(res.begin(), res.end());
return res;
}
// cf. https://qiita.com/drken/items/a14e9af0ca2d857dad23
map<ll, ll> prime_factors(ll n) {
map<ll, ll> res;
// sqrt(n)
for (ll a = 2; a * a <= n; a++) {
if (n % a != 0) continue;
// n
while (n % a == 0) {
res[a]++;
n /= a;
}
}
if (n != 1) res[n]++;
return res;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
// p/q
struct fraction {
ll p, q;
fraction(ll _p = 0, ll _q = 1) : p(_p), q(_q) {
if (q == 0) {
p = 1;
return;
}
if (q < 0) {
p = -p;
q = -q;
}
ll g = gcd(p, q);
p /= g;
q /= g;
}
bool operator<(const fraction& other) const {
return p * other.q < q * other.p;
}
bool operator<=(const fraction& other) const {
return p * other.q <= q * other.p;
}
bool operator==(const fraction& other) const {
return p == other.p && q == other.q;
}
};
// res[i][c] := i c index ( n)
vector<vector<ll>> calcNext(const string& S) {
ll n = (ll)S.size();
vector<vector<ll>> res(n + 1, vector<ll>(26, n));
for (ll i = n - 1; i >= 0; --i) {
for (ll j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
res[i][S[i] - 'a'] = i;
}
return res;
}
// ref. https://algo-logic.info/bridge-lowlink/
struct LowLink {
vector<vector<ll>> G;
vector<ll> ord, low;
vector<bool> visited;
vector<pair<ll, ll>> bridges;
LowLink(const vector<vector<ll>>& _G) : G(_G) {
visited.resize(G.size(), false);
ord.resize(G.size(), 0);
low.resize(G.size(), 0);
ll k = 0;
rep(i, (ll)G.size()) {
if (visited[i]) continue;
k = dfs(i, k);
}
}
ll dfs(ll node, ll k, ll parent = -1) {
visited[node] = true;
ord[node] = k;
low[node] = k;
k++;
for (auto g : G[node]) {
if (!visited[g]) {
k = dfs(g, k, node);
low[node] = min(low[node], low[g]);
if (ord[node] < low[g]) {
bridges.emplace_back(node, g);
}
} else if (g != parent) {
low[node] = min(low[node], ord[g]);
}
}
return k;
}
};
// 3x3()
struct matrix {
vector<vector<ll>> a;
matrix(const vector<vector<ll>>& _a = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}})
: a(_a) {}
matrix operator*(const matrix& x) {
matrix res({{0, 0, 0}, {0, 0, 0}, {0, 0, 0}});
rep(i, 3) rep(j, 3) rep(k, 3) {
// cout << i << "," << j << " <- " << a[i][k] << "*" << x.a[k][j] << endl;
res.a[i][j] += a[i][k] * x.a[k][j];
}
return res;
}
vector<ll> operator*(const vector<ll>& x) {
matrix other({{x[0], 0, 0}, {x[1], 0, 0}, {1, 0, 0}});
auto res = *this * other;
return vector<ll>({res.a[0][0], res.a[1][0], res.a[2][0]});
}
};
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
string S;
cin >> S;
ll N = S.size();
if (N == 1 || N == 2) {
cout << 1 << endl;
return 0;
}
ll ans = 0;
for (ll center = 0; center < N; center++) {
ll l = center - 1;
ll r = center + 1;
ll len = 1;
while (l >= 0 && r < N) {
if (S[l] == S[r]) {
len += 2;
} else {
}
l--;
r++;
}
chmax(ans, len);
}
for (ll i = 0; i < N; i++) {
ll l = i;
ll r = l + 1;
ll len = 0;
while (l >= 0 && r < N) {
if (S[l] == S[r]) {
len += 2;
}
l--;
r++;
}
chmax(ans, len);
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0