結果
問題 | No.464 PPAP |
ユーザー |
![]() |
提出日時 | 2016-12-15 22:12:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 136 ms / 2,000 ms |
コード長 | 2,169 bytes |
コンパイル時間 | 732 ms |
コンパイル使用メモリ | 90,652 KB |
実行使用メモリ | 28,288 KB |
最終ジャッジ日時 | 2024-11-30 08:37:32 |
合計ジャッジ時間 | 2,322 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 22 |
ソースコード
// #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;#elsetypedef long double rn;#endiftypedef 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;}