結果

問題 No.528 10^9と10^9+7と回文
ユーザー HachimoriHachimori
提出日時 2017-06-10 00:40:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,877 bytes
コンパイル時間 1,017 ms
コンパイル使用メモリ 61,552 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 04:20:12
合計ジャッジ時間 2,453 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 WA -
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 94 ms
4,348 KB
testcase_13 AC 94 ms
4,348 KB
testcase_14 AC 53 ms
4,348 KB
testcase_15 AC 46 ms
4,348 KB
testcase_16 AC 43 ms
4,348 KB
testcase_17 AC 35 ms
4,348 KB
testcase_18 AC 89 ms
4,348 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 35 ms
4,348 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 94 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;
const int DIGIT = 100005;
const int MOD_10_9   = 1000000000;
const int MOD_10_9_7 = 1000000007;

int nDigit;
int digit[DIGIT];

void read() {
    string s;
    cin >> s;
    nDigit = s.size();
    for (int i = 0; i < nDigit; ++i) {
        digit[i] = s[i] - '0';
    }
}

int mypow(int p, int n, int mod) {
    if (n == 0) return 1;
    int t = mypow(p, n / 2, mod);
    return n & 1 ? 1LL * t * t % mod * p % mod : 1LL * t * t % mod;
}

void work() {
    int remainDigit = nDigit;
    int sum_10_9   = 0;
    int sum_10_9_7 = 0;
    
    for (int idx = 0; remainDigit > 0; remainDigit -= 2, ++idx) {
        if (idx == 0) {
            sum_10_9   = (sum_10_9   + 1LL * (digit[idx] - 1) * mypow(10, (remainDigit - 1) / 2, MOD_10_9  )) % MOD_10_9  ;
            sum_10_9_7 = (sum_10_9_7 + 1LL * (digit[idx] - 1) * mypow(10, (remainDigit - 1) / 2, MOD_10_9_7)) % MOD_10_9_7;
        } else {
            sum_10_9   = (sum_10_9   + 1LL * (digit[idx]    ) * mypow(10, (remainDigit - 1) / 2, MOD_10_9  )) % MOD_10_9  ;
            sum_10_9_7 = (sum_10_9_7 + 1LL * (digit[idx]    ) * mypow(10, (remainDigit - 1) / 2, MOD_10_9_7)) % MOD_10_9_7;
        }
    }

    for (int curNDigit = 1; curNDigit < nDigit; ++curNDigit) {
        sum_10_9   = (sum_10_9   + 1LL * 9 * mypow(10, (curNDigit - 1) / 2, MOD_10_9  )) % MOD_10_9  ;
        sum_10_9_7 = (sum_10_9_7 + 1LL * 9 * mypow(10, (curNDigit - 1) / 2, MOD_10_9_7)) % MOD_10_9_7;
    }


    bool lastPalindrome = true;
    for (int i = 0; i < nDigit / 2; ++i) {
        if (digit[nDigit / 2 - i - 1] > digit[nDigit / 2 + i - 1]) {
            lastPalindrome = false;
            break;
        }
    }
    
    cout << (sum_10_9   + lastPalindrome) % MOD_10_9   << endl;
    cout << (sum_10_9_7 + lastPalindrome) % MOD_10_9_7 << endl;
}


int main() {
    read();
    work();
    return 0;
}
0