結果

問題 No.599 回文かい
コンテスト
ユーザー conf
提出日時 2017-03-18 01:23:30
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 825 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 301 ms
コンパイル使用メモリ 62,336 KB
最終ジャッジ日時 2026-03-25 21:50:45
合計ジャッジ時間 620 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:4:1: error: 'uint64_t' does not name a type
    4 | uint64_t DP[5002];
      | ^~~~~~~~
main.cpp:2:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    1 | #include <iostream>
  +++ |+#include <cstdint>
    2 | using namespace std;
main.cpp:6:1: error: 'uint64_t' does not name a type
    6 | uint64_t mod_pow(uint64_t a, uint64_t e, uint64_t p){
      | ^~~~~~~~
main.cpp:6:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
main.cpp: In function 'int main()':
main.cpp:18:5: error: 'uint64_t' was not declared in this scope
   18 |     uint64_t ans = 1;
      |     ^~~~~~~~
main.cpp:18:5: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
main.cpp:19:5: error: 'DP' was not declared in this scope
   19 |     DP[0]=1;
      |     ^~
main.cpp:20:13: error: expected ';' before 'base'
   20 |     uint64_t base=1009,mod=1000000007,hl,hr;
      |             ^~~~~
      |             ;
main.cpp:22:9: error: 'hl' was not declared in this scope
   22 |         hl=0;hr=0;
      |         ^~
main.cpp:22:14: error: 'hr' was not declared in this scope
   22 |         hl=0;hr=0;
      |              ^~
main.cpp:24:20: error: 'base' was not declared in this scope
   24 |             hl=(hl*base+S[j])%mod;
      |                    ^~~~
main.cpp:24:31: error: 'mod' was not declared in this scope
   24 |             hl=(hl*base+S[j])%mod;
      |                               ^~~
main.cpp:25:20: error: 'mod_pow' was not declared in this scope
   25 |             hr=(hr+mod_pow(base,i-j,mod)*S[S.size()-j-1])%mod;
      |                    ^~~~~~~
main.cpp:32:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   32 |         ans+=DP[i+1];
      |         ^~~
      |         abs
main.cpp:33:14: error: 'mod' was not declared in this scope
   33 |         ans%=mod;
      |              ^~~
m

ソースコード

diff #
raw source code

#include <iostream>
using namespace std;

uint64_t DP[5002];

uint64_t mod_pow(uint64_t a, uint64_t e, uint64_t p){
    uint64_t res = 1;
    for(;e>0;e>>=1){
        if(e&1)res=(res*a)%p;
        a=(a*a)%p;
    }
    return res;
}

int main(){
    string S;
    cin>>S;
    uint64_t ans = 1;
    DP[0]=1;
    uint64_t base=1009,mod=1000000007,hl,hr;
    for(int i=0;i<S.size()/2;i++){
        hl=0;hr=0;
        for(int j=i;j>=0;j--){
            hl=(hl*base+S[j])%mod;
            hr=(hr+mod_pow(base,i-j,mod)*S[S.size()-j-1])%mod;
            // cout<<S.substr(j,i-j+1)<<' '<<S.substr(S.size()-i-1,i-j+1)<<' '<<hl<<' '<<hr<<endl;
            if(hl==hr){
                DP[i+1]+=DP[j];
                DP[i+1]%=mod;
            }
        }
        ans+=DP[i+1];
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}
0