結果

問題 No.464 PPAP
ユーザー face4face4
提出日時 2018-11-12 17:46:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 813 bytes
コンパイル時間 736 ms
コンパイル使用メモリ 72,452 KB
実行使用メモリ 18,344 KB
最終ジャッジ日時 2023-08-25 02:43:29
合計ジャッジ時間 5,088 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

string s;

bool isPalindrome(int i, int j){
    for(int k = 0; k <= (j-i)/2; k++){
        if(s[i+k] != s[j-k])    return false;
    }
    return true;
}

int main(){
    cin >> s;
    
    int n = s.length();
    vector<int> v[n], aft(n, 0);

    for(int i = 0; i < n; i++){
        for(int j = i; j < n-2; j++){
            if(isPalindrome(i,j))   v[i].push_back(j);
        }
    }

    for(int i = 0; i < n; i++){
        if(isPalindrome(i, n-1))    aft[i] = 1;
    }

    for(int i = n-2; i >= 0; i--)   aft[i] += aft[i+1];

    // 最悪計算量はO(n^2)なので間に合うはず...?
    long long ans = 0;
    for(int i : v[0]){
        for(int j : v[i+1]){
            ans += aft[j+2];
        }
    }

    cout << ans << endl;

    return 0;
}
0