結果

問題 No.464 PPAP
ユーザー milanis48663220milanis48663220
提出日時 2020-06-28 13:17:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,336 bytes
コンパイル時間 827 ms
コンパイル使用メモリ 89,476 KB
実行使用メモリ 141,816 KB
最終ジャッジ日時 2023-09-21 19:56:49
合計ジャッジ時間 6,380 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 67 ms
9,132 KB
testcase_08 AC 27 ms
7,416 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 TLE -
testcase_11 AC 176 ms
25,020 KB
testcase_12 AC 335 ms
41,576 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 1,061 ms
93,232 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 4 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();
    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 i : v[1]) cout << i << ' ';
    // cout << endl;
    for(int l : v[0]){
        for(int r : u[n-1]){
            int l1 = l+1;
            // r1 < r-1
            auto p = upper_bound(v[l1].begin(), v[l1].end(), r-2);
            ans += p-v[l1].begin();
            // cout << l << ' ' << r << ' ' << p-v[l1].begin() << endl; 
        }
    }
    cout << ans << endl;
}
0