結果

問題 No.528 10^9と10^9+7と回文
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-06-09 23:15:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,801 bytes
コンパイル時間 1,810 ms
コンパイル使用メモリ 168,604 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 01:26:37
合計ジャッジ時間 3,898 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
int add(int mod, int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int mod, int x, T... y) { return add(mod, x, add(mod, y...)); }
int mul(int mod, int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int mod, int x, T... y) { return mul(mod, x, mul(mod, y...)); }
int sub(int mod, int x, int y) { return add(mod, x, mod - y); }
int modpow(int mod, int a, long long b) {
    int ret = 1; while (b > 0) {
        if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1;
    } return ret;
}
int modinv(int mod, int a) { return modpow(mod, a, mod - 2); }
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




string N;
//---------------------------------------------------------------------------------------------------
int solve(int mod) {
    int n = N.length();
    int ans = 0;

    rep(len, 1, n) {
        int res = 9;
        if (len == 1) {
            ans = res;
            continue;
        }
        res = mul(mod, res, modpow(mod, 10, (len - 1) / 2));
        ans = add(mod, ans, res);
    }

    rep(i, 0, n / 2) {
        int c = N[i] - '0';
        if (0 < c) ans = add(mod, ans, mul(mod, c - 1, modpow(mod, 10, n / 2 - i - 1)));
    }

    if (n % 2 == 0) {
        bool ok = true;
        rep(i, 0, n / 2) {
            if (N[n / 2 - 1 - i] < N[i + n / 2]) ok = false;
            if (N[n / 2 - 1 - i] > N[i + n / 2]) break;
        }
        if (ok) ans = add(mod, ans, 1);
    } else {
        int c = N[n / 2] - '0';
        ans = add(mod, ans, c);

        bool ok = true;
        rep(i, 0, n / 2) {
            if (N[n / 2 - 1 - i] < N[i + n / 2 + 1]) ok = false;
            if (N[n / 2 - 1 - i] > N[i + n / 2 + 1]) break;
        }
        if (ok) ans = add(mod, ans, 1);
        ans = sub(mod, ans, 1);
    }

    return ans;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    cout << solve(1000000000) << endl;
    cout << solve(1000000007) << endl;
}
0