結果

問題 No.464 PPAP
ユーザー chaemonchaemon
提出日時 2016-12-15 22:12:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 2,169 bytes
コンパイル時間 741 ms
コンパイル使用メモリ 82,992 KB
実行使用メモリ 28,380 KB
最終ジャッジ日時 2023-08-20 07:45:21
合計ジャッジ時間 2,911 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 6 ms
9,412 KB
testcase_08 AC 6 ms
9,448 KB
testcase_09 AC 6 ms
9,404 KB
testcase_10 AC 150 ms
28,176 KB
testcase_11 AC 93 ms
23,824 KB
testcase_12 AC 150 ms
28,192 KB
testcase_13 AC 134 ms
28,152 KB
testcase_14 AC 137 ms
28,128 KB
testcase_15 AC 2 ms
4,380 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,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 129 ms
28,204 KB
testcase_24 AC 134 ms
28,380 KB
testcase_25 AC 136 ms
28,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #includes {{{
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cmath>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
#ifdef __MINGW32__
typedef double rn;
#else
typedef long double rn;
#endif

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

bool is_p[5050][5050];
Int dp[5][5050];

string S;

Int calc(int i=0,int j=0){
	Int &ret = dp[i][j];
	if(ret!=-1)return ret;
	if(i==4){
		if(j==S.size())return ret=1;
		else return ret=0;
	}
	Int ans = 0;
	for(int j2=j+1;j2<=S.size();j2++){
		if(i==2 or is_p[j][j2-j]){
			ans += calc(i+1,j2);
		}
	}
//	cout<<i<<" "<<j<<" "<<ans<<endl;
	return ret = ans;
}

int main(){
	cin>>S;
	REP(i,S.size())is_p[i][0] = true;
	REP(i,S.size())is_p[i][1] = true;
	for(int d=2;d<S.size();d++){
		for(int i=0;i<S.size();i++){
			int j = i+d;
			if(j>S.size())break;
			if(S[i]==S[i+d-1] and is_p[i+1][d-2])is_p[i][d] = true;
			else is_p[i][d] = false;
		}
	}
	memset(dp,-1,sizeof(dp));
	cout<<calc()<<endl;
	return 0;
}
0