結果

問題 No.464 PPAP
ユーザー milanis48663220milanis48663220
提出日時 2020-06-28 13:35:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,394 bytes
コンパイル時間 890 ms
コンパイル使用メモリ 94,228 KB
実行使用メモリ 92,772 KB
最終ジャッジ日時 2023-09-21 20:31:01
合計ジャッジ時間 3,351 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 25 ms
7,436 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 156 ms
25,036 KB
testcase_12 AC 299 ms
41,544 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 955 ms
92,772 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

vector<int> v[5000], u[5000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    string s;
    cin >> s;
    int n = s.size();
    set<int> st;
    for(char c : s) st.insert(c);
    if(st.size() == 1) {
        ll ans = ((n-1)*(n-2)*(n-3))/6;
        cout << ans << endl;
        return 0;
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; i-j >= 0 && i+j < n; j++){
            int l = i-j, r = i+j;
            if(s[l] != s[r]) break;
            v[l].push_back(r);
            u[r].push_back(l);
        }
    }
    for(int i = 0; i < n-1; i++){
        for(int j = 0; i-j >= 0 && i+j+1 < n; j++){
            int l = i-j, r = i+j+1;
            if(s[l] != s[r]) break;
            v[l].push_back(r);
            u[r].push_back(l);
        }
    }
    for(int i = 0; i < n; i++) {
        sort(v[i].begin(), v[i].end());
        sort(u[i].begin(), u[i].end());
    }
    ll ans = 0;
    for(int l : v[0]){
        int l1 = l+1;
        int idx = 0;
        for(int r : u[n-1]){
            if(r <= l) continue;
            auto p = upper_bound(v[l1].begin(), v[l1].end(), r-2);
            ans += p-v[l1].begin();
        }
    }
    cout << ans << endl;
}
0