結果

問題 No.273 回文分解
ユーザー rogi52rogi52
提出日時 2022-09-28 18:53:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,243 bytes
コンパイル時間 2,072 ms
コンパイル使用メモリ 201,152 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 04:32:35
合計ジャッジ時間 4,462 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 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 WA -
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 WA -
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 WA -
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

namespace pal {

enum {even, odd, merge};

template < int type = odd >
vector<int> manacher(string s) {
    if(type == even || type == merge) {
        int n = int(s.size());
        string t(2 * n - 1, '$');
        for(int i = 0; i < n; i++) t[2 * i] = s[i];
        swap(s, t);
    }

    int n = int(s.size());
    vector<int> R(n);
    for(int i = 0, j = 0, k; i < n; i += k, j -= k) {
        while(0 <= i - j && i + j < n && s[i - j] == s[i + j]) j++;
        R[i] = j;
        for(k = 1; 0 <= i - k && i + k < n && k + R[i - k] < j; k++) R[i + k] = R[i - k];
    }

    if(type == odd)
        for(int i = 0; i < n; i++) R[i] = 2 * R[i] - 1;
    if(type == even) {
        for(int i = 1; i < n - 1; i += 2) R[i / 2] = R[i] - (!((i ^ R[i]) & 1));
        for(int i = 0; i < n; i += 2) R.pop_back();
    }
    if(type == merge)
        for(int i = 0; i < n; i++) if(!((i ^ R[i]) & 1)) R[i]--;

    return R;
}

} // namespace pal

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    string S; cin >> S;
    vector<int> A = pal::manacher<pal::merge>(S);
    cout << *max_element(A.begin(), A.end()) << endl;
}
0