結果

問題 No.464 PPAP
ユーザー Hoi_koroHoi_koro
提出日時 2016-12-19 17:17:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,633 ms / 2,000 ms
コード長 2,297 bytes
コンパイル時間 1,180 ms
コンパイル使用メモリ 118,012 KB
実行使用メモリ 4,424 KB
最終ジャッジ日時 2023-08-21 01:18:42
合計ジャッジ時間 4,810 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
#include <random>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define dump(a) cerr<<#a <<' '<< a <<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
typedef pair<int,int>PI; typedef vector<int> VI;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;

long long modpow(long long a, long long n){
    if(n==0) return 1;
    long long re=modpow((a*a)%MOD,n/2)%MOD;
    if(n%2==1) re= (re*a)%MOD;
    return re;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    LL l=s.size();
    LL p[3]={999999937,MOD,MOD+2};
    LL b[3]={149853437,2345752,564565};
    vector<VLL> rh(l+2,VLL(3)), revh(l+2,VLL(3));
    vector<VLL> power(l+2,VLL(3));
    REP(i,3) power[0][i]=1;
    FOR(i,1,l+1){
        REP(j,3){
            rh[i][j]=(rh[i-1][j]*b[j]+(s[i-1]-' '))%p[j];
            revh[i][j]=(revh[i-1][j]*b[j]+(s[l-i]-' '))%p[j];
            power[i][j]=power[i-1][j]*b[j]%p[j];
        }
    }

    auto ok=[&](int a,int b){
        REP(i,3){
            if((rh[b][i]-(rh[a-1][i]*power[b-a+1][i]%p[i])+p[i])%p[i]!=(revh[l-a+1][i]-(revh[l-b][i]*power[b-a+1][i]%p[i])+p[i])%p[i]) return false;
        }
        return true;
    };

    VLL p3(l+2);
    for(int i=l;i>=4;--i){
        if(ok(i,l)){
            p3[i]=p3[i+1]+1;
        }else{
            p3[i]=p3[i+1];
        }
    }
    LL ans=0;
    FOR(i,1,l-2){
        if(ok(1,i)){
            FOR(j,i+1,l-1){
                if(ok(i+1,j)){
                    ans=ans+p3[j+2];
                }
            }
        }
    }

    cout<< ans <<endl;

    return 0;
}
0