結果

問題 No.599 回文かい
コンテスト
ユーザー illanasty
提出日時 2021-12-02 15:21:35
言語 C++17(clang)
(clang++ 21.1.8 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,632 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,361 ms
コンパイル使用メモリ 152,924 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-26 08:32:26
合計ジャッジ時間 4,289 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>


using namespace std;


using ll = long long;
using ld = long double;


#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)


template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template<class T> using pq  = priority_queue<T>;


template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return true; } return false; }


constexpr int MOD = 1000000007;


int pow2[10005];


int main() {
  string s;
  cin >> s;

  int n = s.size();

  pow2[0] = 1;
  rep(i, 10004) pow2[i+1] = (pow2[i] * 2) % MOD;

  vector<string> ts;
  int sum = 0;
  string a, b, c;

  rep(i, n/2) {
    a += s[i];
    b = s[n-i-1] + b;

    if (a == b) {
      ts.push_back(a);
      sum += a.size();
      a = b = "";
    }
  }

  c = s.substr(sum, n - 2 * sum);

  int ans = 0, streak = 0;
  string last;

  for (string t : ts) {
    if (t == last) {
      ++streak;
    } else {
      ans += pow2[streak];
      ans %= MOD;
      streak = 0;
    }
  }

  bool isPalin = false;
  string d = c;
  reverse(all(c));

  if (d == c) isPalin = true;

  if (isPalin) ans += ts.size();
  else ++ans;
  
  ans %= MOD;
  cout << ans << endl;

  return 0;
}
0