結果

問題 No.528 10^9と10^9+7と回文
ユーザー h_nosonh_noson
提出日時 2017-06-10 00:25:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,576 bytes
コンパイル時間 850 ms
コンパイル使用メモリ 84,024 KB
実行使用メモリ 4,596 KB
最終ジャッジ日時 2023-10-24 04:10:02
合計ジャッジ時間 2,283 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 26 ms
4,596 KB
testcase_12 AC 25 ms
4,596 KB
testcase_13 WA -
testcase_14 AC 16 ms
4,348 KB
testcase_15 AC 14 ms
4,348 KB
testcase_16 AC 14 ms
4,348 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 8 ms
4,348 KB
testcase_20 WA -
testcase_21 AC 12 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 5 ms
4,348 KB
testcase_26 AC 26 ms
4,596 KB
testcase_27 AC 20 ms
4,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int dp[2][50001][2];

int main(void) {
    string s;
    cin >> s;
    int i, j, k, l, n = s.size();
    int mod[2];
    mod[0] = 1e9;
    mod[1] = 1e9+7;
    dp[0][0][1] = 1;
    dp[1][0][1] = 1;
    REP (i,2) REP (j,(n+1)/2) REP (k,10) {
        if (j == 0 && k == 0) continue;
        dp[i][j+1][0] = (dp[i][j+1][0] + dp[i][j][0]) % mod[i];
        if (k < s[j] - '0') dp[i][j+1][0] = (dp[i][j+1][0] + dp[i][j][1]) % mod[i];
        if (k == s[j] - '0') dp[i][j+1][1] = (dp[i][j+1][1] + dp[i][j][1]) % mod[i];
    }
    int ans[2] {};
    long long x[2] {9,9};
    REP (i,2) REP (j,n/2) {
        ans[i] = (ans[i] + x[i]) % mod[i];
        if ((j+1) * 2 <= n-1)
            ans[i] = (ans[i] + x[i]) % mod[i];
        x[i] = (x[i] * 10) % mod[i];
    }
    REP (i,2) ans[i] = (ans[i] + dp[i][(n+1)/2][0]) % mod[i];
    bool ok = true;
    REP (i,n/2) {
        if (s[i] < s[n-1-i]) break;
        ok &= s[i] == s[n-1-i];
    }
    REP (i,2) ans[i] = (ans[i] + ok) % mod[i];
    REP (i,2) cout << ans[i] << endl;
    return 0;
}
0