結果

問題 No.599 回文かい
ユーザー ikdikd
提出日時 2017-11-25 15:09:34
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 241 ms / 4,000 ms
コード長 1,075 bytes
コンパイル時間 734 ms
コンパイル使用メモリ 78,564 KB
実行使用メモリ 111,628 KB
最終ジャッジ日時 2023-09-03 17:04:06
合計ジャッジ時間 2,502 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,504 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 136 ms
91,180 KB
testcase_15 AC 9 ms
7,772 KB
testcase_16 AC 212 ms
98,016 KB
testcase_17 AC 241 ms
111,628 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
evil_0.txt AC 56 ms
39,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  auto s=readln.chomp.to!(char[]);
  
  int[] zAlgorithm(char[] _s){
    auto _n=to!(int)(_s.length);
    auto z=new int[](_n);
    if(_n==0) return z;
    z[0]=_n;
    int _i=1, _j=0; // s[0, j), s[i, i+j)
    while(_i<_n){
      while(_i+_j<_n && _s[_j]==_s[_i+_j]) _j++;
      z[_i]=_j;
      if(_j==0){_i++; continue;}
      auto k=1;
      while(_i+k<_n && k+z[k]<_j) z[_i+k]=z[k], k++; // s[k, k+z[k]) in s[k, j)
      _i+=k; _j-=k; // s[0, j-k) == s[i+k, j)
    }
    return z;
  }

  auto mm=new long[](s.length/2+1);
  fill(mm, -1);
  const long mod=1_000_000_000+7;
  long fun(int i){
    if(mm[i]>=0) return mm[i];
    auto t=s[i..($-i)];
    long ret=1;
    auto z=zAlgorithm(t);
    for(int j=1; j<=(t.length/2); j++){
      if(j==z[$-j]) (ret+=fun(i+j))%=mod;
    }
    return mm[i]=ret;
  }

  writeln(fun(0));
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
0