結果

問題 No.464 PPAP
ユーザー tubo28tubo28
提出日時 2017-02-11 11:03:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,956 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 169,940 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 12:48:49
合計ジャッジ時間 2,877 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

std::vector<int> manachar(const std::string &s) {
  int n = s.size();
  std::vector<int> rad(n);
  int c = 0;
  for (int r = 0; r < n; ++r) {
    int l = c - (r - c);
    if (r + rad[l] < c + rad[c]) {
      rad[r] = rad[l];
    } else {
      int rr = c + rad[c];
      int rl = r - (rr - r);
      while (rl >= 0 && rr < n && s[rl] == s[rr])
        ++rr, --rl;
      rad[r] = rr - r;
      c = r;
    }
  }
  return rad;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
template<typename T> void __dump__(const T &first){ std::cerr << first << std::endl; }
template<typename First, typename... Rest>
void __dump__(const First& first, const Rest&... rest) { std::cerr << first << ", "; __dump__(rest...); }
#define dump(...) { std::cerr << __LINE__ << ":\t" #__VA_ARGS__ " = "; __dump__(__VA_ARGS__); }

string s;
int n;

vector<int> rad;

// [l, r)
bool is_pal(int l, int r){
    l = l*2 + 1;
    r = (r-1)*2 + 1;
    int c = (l + r) / 2;
    return r < c + rad[c];
}

int main(){
    while(cin >> s){
        int n = s.size();
        string t = "$";
        rep(i, n){
            t += s[i];
            t += '$';
        }
        s = t;
        rad = manachar(s);
        int pp[5010] = {};
        for(int i = 1; i < n; ++i){
            for(int j = i + 1; j <= n; ++j){
                if(is_pal(0, i) && is_pal(i, j)){
                    ++pp[j];
                }
            }
        }
        ll ans = 0;
        for(int i = 2; i < n; ++i){
            for(int j = i + 1; j < n; ++j){
                ans += (ll)pp[i] * is_pal(j, n);
            }
        }
        cout << ans << endl;
    }
}
0