結果

問題 No.599 回文かい
ユーザー shung11260shung11260
提出日時 2019-10-13 18:34:27
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,324 bytes
コンパイル時間 637 ms
コンパイル使用メモリ 62,712 KB
実行使用メモリ 10,276 KB
最終ジャッジ日時 2024-05-09 16:04:39
合計ジャッジ時間 6,420 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>

const long long int MOD=1e9+7;
const long long int BASE=31;

using namespace std;

struct RollingHush {
    vector<long long int> hash;
    vector<long long int> power;
    string str;
    
    RollingHush(string s) : hash(s.size()+1), power(s.size()+1) {
        str=s;
        hash[0]=0;
        power[0]=1;
        for(int si=0; si<s.size(); si++) {
            long long int s2lli=s[si];
            s2lli %= BASE;
            
            hash[si+1] = (hash[si]*BASE+s2lli)%MOD;
            power[si+1] = power[si]*BASE%MOD;
        }
    }
    
    long long int get(int left, int right) {
        return ((hash[right]-hash[left]*power[right-left])%MOD+MOD)%MOD;
    }

    int size() {
        return str.size();
    }
};

long long int count_kaibunkai(RollingHush rh, int left, int right) {
    long long int count=1;
    if(right-left<=1) {
        return 1;
    }
    int mid=(left+right)/2;
    while(left<mid) {
        if(rh.get(left, mid)==rh.get(right+left-mid, right)) {
            count += count_kaibunkai(rh, mid, right+left-mid);
        }
        mid--;
    }
    return count;
}

int main() {
    string str;
    cin >> str;
    
    RollingHush rh_str(str);
    
    cout << count_kaibunkai(rh_str, 0, str.size()) << endl;

    return 0;
    
}
0