結果

問題 No.464 PPAP
ユーザー milanis48663220milanis48663220
提出日時 2020-06-28 13:39:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 970 ms / 2,000 ms
コード長 1,393 bytes
コンパイル時間 962 ms
コンパイル使用メモリ 94,192 KB
実行使用メモリ 92,796 KB
最終ジャッジ日時 2023-09-21 20:37:17
合計ジャッジ時間 3,706 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 24 ms
7,492 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 154 ms
25,076 KB
testcase_12 AC 299 ms
41,612 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 970 ms
92,796 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 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;
    ll 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