結果

問題 No.599 回文かい
ユーザー tnakao0123
提出日時 2017-11-25 20:02:29
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 169 ms / 4,000 ms
コード長 1,957 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 84,640 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-27 10:06:31
合計ジャッジ時間 2,188 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:75:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   75 |   scanf("%s", s);
      |   ~~~~~^~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

/* -*- coding: utf-8 -*-
*
* 599.cc: No.599 - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 10000;
const int MAX_HN = MAX_N / 2;
const int MOD = 1000000007;
const int P0 = 6779, M0 = 12853;
const int P1 = 4289, M1 = 10799;
/* typedef */
typedef long long ll;
/* global variables */
char s[MAX_N + 10];
ll dp[MAX_HN + 1];
int rh0[MAX_N + 1], rh1[MAX_N + 1];
int rpe0[MAX_N], rpe1[MAX_N];
/* subroutines */
int powmod(int a, int b, int mod) {
int p = 1;
while (b) {
if (b & 1) p = (p * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return p;
}
inline int rhash(int rh[], int rpe[], int i, int j, int mod) {
return (rh[j] - rh[i] + mod) % mod * rpe[i] % mod;
}
bool kaibunkai(int n, int i, int j) {
if ((rhash(rh0, rpe0, i, j, M0) != rhash(rh0, rpe0, n - j, n - i, M0)) ||
(rhash(rh1, rpe1, i, j, M1) != rhash(rh1, rpe1, n - j, n - i, M1)))
return false;
//for (int i0 = i, i1 = n - j; i0 < j; i0++, i1++)
//if (s[i0] != s[i1]) return false;
return true;
}
/* main */
int main() {
scanf("%s", s);
int n = strlen(s), hn = n / 2;
rh0[0] = rh1[0] = 0;
int pe0 = 1, pe1 = 1;
for (int i = 0; i < n; i++) {
int d = s[i] - '0';
rh0[i + 1] = (rh0[i] + d * pe0) % M0;
rh1[i + 1] = (rh1[i] + d * pe1) % M1;
rpe0[i] = powmod(pe0, M0 - 2, M0);
rpe1[i] = powmod(pe1, M1 - 2, M1);
pe0 = (pe0 * P0) % M0;
pe1 = (pe1 * P1) % M1;
}
fill(dp, dp + hn + 1, 1);
for (int i = hn - 1; i >= 0; i--)
for (int j = i + 1; j <= hn; j++)
if (kaibunkai(n, i, j)) dp[i] = (dp[i] + dp[j]) % MOD;
printf("%lld\n", dp[0]);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0