結果

問題 No.599 回文かい
ユーザー okayunonahaokayunonaha
提出日時 2017-11-24 23:13:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 577 bytes
コンパイル時間 1,894 ms
コンパイル使用メモリ 174,056 KB
実行使用メモリ 5,016 KB
最終ジャッジ日時 2023-08-18 05:14:02
合計ジャッジ時間 11,558 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 7 ms
4,384 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
evil_0.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int n;
string s;
map<pair<int, int>, int> mp;

int solve(int l, int r) {
  if (mp[{l, r}] != 0) return mp[{l, r}];

  int ret = 1;
  string a, b;
  a = "", b = "";
  for (int i = 0; i + l < n / 2; ++i) {
    a += s[l + i], b = s[r - i] + b;    
    if (a == b) {
      ret += (solve(l + i + 1, r - i - 1)) % 1000000007;
    }
  }

  return mp[{l, r}] = ret % 1000000007;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s;
  n = s.size();

  auto ans = solve(0, n - 1);

  cout << ans << endl;

  return 0;
}
0