結果

問題 No.465 PPPPPPPPPPPPPPPPAPPPPPPPP
ユーザー pekempeypekempey
提出日時 2016-12-16 08:12:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,636 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 173,784 KB
実行使用メモリ 11,296 KB
最終ジャッジ日時 2024-05-07 16:01:17
合計ジャッジ時間 5,495 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 1 ms
5,376 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 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 -- -
testcase_21 -- -
32_ratsliveonnoevilstar.txt -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

bool isPalindrome(const string &s, int l, int r) {
    for (int i = 0; i < r - l; i++) {
        if (s[l + i] != s[r - 1 - i]) {
            return false;
        }
    }
    return true;
}

bool isPalTwo(const string &s, int l, int r) {
    if (r - l <= 1) {
        return false;
    }
    for (int i = 1; i < r - l; i++) {
        if (isPalindrome(s, l, l + i) && isPalindrome(s, l + i, r)) {
            return true;
        }
    }
    return false;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();

    vector<bool> bad(n);
    vector<int64_t> cnt(n + 2);
    for (int i = 1; i < n; i++) {
        if (bad[i]) {
            continue;
        }
        if (isPalindrome(s, 0, i)) {
            for (int j = 2; i * j < n; j++) {
                if (s.substr(0, i) != s.substr(i * (j - 1), i)) {
                    break;
                }
                cnt[i * j + 1] += j - 1;
                bad[i * j] = true;
            }
        }
    }
    for (int i = 2; i <= n - 2; i++) {
        if (bad[i]) {
            continue;
        }
        if (isPalTwo(s, 0, i)) {
            for (int j = 1; i * j < n; j++) {
                if (s.substr(0, i) != s.substr(i * (j - 1), i)) {
                    break;
                }
                cnt[i * j + 1] += j;
                bad[i * j] = true;
            }
        }
    }

    for (int i = 0; i < n - 1; i++) {
        cnt[i + 1] += cnt[i];
    }

    int64_t ans = 0;
    for (int i = 0; i < n; i++) {
        if (isPalindrome(s, i, n)) {
            ans += cnt[i];
        }
    }
    cout << ans << endl;
}
0