結果

問題 No.765 ukuku 2
ユーザー treeonetreeone
提出日時 2018-11-25 22:01:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,616 bytes
コンパイル時間 2,401 ms
コンパイル使用メモリ 211,472 KB
実行使用メモリ 41,036 KB
最終ジャッジ日時 2023-08-26 19:59:26
合計ジャッジ時間 16,275 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 1 ms
4,380 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 537 ms
32,904 KB
testcase_31 WA -
testcase_32 AC 445 ms
25,396 KB
testcase_33 AC 260 ms
37,800 KB
testcase_34 AC 265 ms
37,656 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 736 ms
40,564 KB
testcase_38 AC 825 ms
41,036 KB
testcase_39 AC 807 ms
39,720 KB
testcase_40 AC 542 ms
33,320 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct RollingHash {
    int n;
    long long base1, base2, mod1, mod2;
    vector<long long> hash1, hash2, pow1, pow2;
    RollingHash(const string &s) : base1(1009), base2(1007), mod1(1000000007), mod2(1000000009) {
        n = s.size();
        hash1.assign(n + 1, 0); hash2.assign(n + 1, 0); pow1.assign(n + 1, 1); pow2.assign(n + 1, 1);
        for(int i = 0; i < n; i++) {
            hash1[i + 1] = (hash1[i] + s[i]) * base1 % mod1;
            hash2[i + 1] = (hash2[i] + s[i]) * base2 % mod2;
            pow1[i + 1] = pow1[i] * base1 % mod1;
            pow2[i + 1] = pow2[i] * base2 % mod2;
        }
    }
    pair<long long, long long> get(int l, int r) {
        long long t1 = ((hash1[r] - hash1[l] * pow1[r - l]) % mod1 + mod1) % mod1;
        long long t2 = ((hash2[r] - hash2[l] * pow2[r - l]) % mod2 + mod2) % mod2;
        return {t1, t2};
    }
    int LCP(int l, int r){
        int len = n - r, low = -1, high = len + 1;
        while(high - low > 1){
            int mid = (low + high) / 2;
            if(get(l, l + mid) == get(r, r + mid)) low = mid;
            else high = mid;
        }
        return low;
    }
};

vector<int> manacher(string &s){
    int i = 0, j = 0;
    vector<int> res(s.size());
    while (i < s.size()) {
        while (i - j >= 0 && i + j < s.size() && s[i - j] == s[i + j]) ++j;
        res[i] = j;
        int k = 1;
        while (i - k >= 0 && i + k < s.size() && k + res[i - k] < j) res[i + k] = res[i - k], ++k;
        i += k; j -= k;
    }
    return res;
}

int main(){
    int ans = 0;
    string s, t = "$";
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        t += s[i]; t += "$";
    }
    s = t;
    vector<int> len = manacher(s), left(s.size()), right(s.size());
    for(int i = 0; i < len.size(); i++){
        len[i]--;
        left[i] = i - len[i];
        right[i] = i + len[i];
    }
    string sr = s;
    reverse(sr.begin(), sr.end());
    string ssr = s + "#" + sr;
    RollingHash rh(ssr);
	vector<int> d;
    for(int i = 0; i < s.size(); i++){
        if(right[i] + 1 <= s.size() - 1){
            int rightStart = right[i] + 3;
            int leftStart = ssr.size() - 1 - (left[i] - 1);
            int lcp = rh.LCP(rightStart, leftStart);
			d.push_back(len[i] + lcp);
        }
        if(left[i] - 1 >= 0){
            int rightStart = right[i] + 1;
            int leftStart = ssr.size() - 1 - (left[i] - 3);
            int lcp = rh.LCP(rightStart, leftStart);
			d.push_back(len[i] + lcp);
        }
    }
	sort(d.rbegin(), d.rend());
	ans = d[1];
    cout << ans << endl;
}
0