結果

問題 No.464 PPAP
ユーザー te-shte-sh
提出日時 2017-12-07 15:53:38
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 426 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 647 ms
コンパイル使用メモリ 77,892 KB
実行使用メモリ 43,108 KB
最終ジャッジ日時 2023-09-03 17:17:47
合計ジャッジ時間 3,626 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 7 ms
4,376 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 426 ms
42,896 KB
testcase_11 AC 144 ms
20,264 KB
testcase_12 AC 229 ms
43,108 KB
testcase_13 AC 133 ms
43,088 KB
testcase_14 AC 224 ms
42,752 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 132 ms
43,072 KB
testcase_24 AC 132 ms
42,584 KB
testcase_25 AC 132 ms
42,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto s = readln.chomp, n = s.length.to!int;

  auto t = new bool[][](n, n);
  foreach (i; 0..n) {
    t[i][i] = true;
    foreach (j; 1..min(i, n-i-1)+1) {
      if (s[i-j] != s[i+j]) break;
      t[i-j][i+j] = true;
    }
  }
  foreach (i; 0..n-1) {
    foreach (j; 1..min(i+1, n-i-1)+1) {
      if (s[i-j+1] != s[i+j]) break;
      t[i-j+1][i+j] = true;
    }
  }

  auto ans = 0L;
  foreach (i; 2..n-1) {
    auto r1 = 0L;
    foreach (j; 1..i)
      if (t[0][j-1] && t[j][i-1]) ++r1;

    auto r2 = 0L;
    foreach (j; 1..n-i)
      if (t[i+j][n-1]) ++r2;

    ans += r1 * r2;
  }

  writeln(ans);
}
0