結果

問題 No.528 10^9と10^9+7と回文
ユーザー parukiparuki
提出日時 2017-06-10 09:42:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,147 bytes
コンパイル時間 1,763 ms
コンパイル使用メモリ 173,696 KB
実行使用メモリ 5,372 KB
最終ジャッジ日時 2023-10-24 20:23:07
合計ジャッジ時間 2,623 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int p1 = (int)1e9, p2 = (int)1e9 + 7;
typedef pair<ll, ll> Val;
Val add(Val x, Val y) {
    (x.first += y.first) %= p1;
    (x.second += y.second) %= p2;
    return x;
}
Val mul(Val x, Val y) {
    (x.first *= y.first) %= p1;
    (x.second *= y.second) %= p2;
    return x;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int l = sz(s);
    string t = s;
    each(c, s)c -= '0';

    if (l == 1) {
        cout << (int)s[0] << endl;
        cout << (int)s[0] << endl;
        return 0;
    }

    Val ans(0, 0);
    ans = add(ans, Val(9, 9));
    Val aa(1, 1);
    for (int i = 2; i < l; ++i) {
        Val x(0, 0);
        if (i % 2) aa = mul(aa, Val(10, 10));
        ans = add(ans, mul(aa, Val(9, 9)));
    }

    vector<Val> pw(l + 1);
    pw[0] = Val(1, 1);
    rep(i, l)pw[i + 1] = mul(pw[i], Val(10, 10));
    bool les = false;
    rep(i, l / 2) {
        if (!les && i > 0 && s[i - 1] > s[l - 1 - (i - 1)]) {
            break;
        }
        if (s[i] < s[l - 1 - i])les = true;
        int float_len = (l - (i + 1) * 2 + 1) / 2;
        if (s[i] > 1 || (i > 0 && s[i] > 0)) {
            if(i>0)ans = add(ans, mul(Val(s[i], s[i]), pw[float_len]));
            else ans = add(ans, mul(Val(s[i] - 1, s[i] - 1), pw[float_len]));
        }
    }

    string pre = t.substr(0, l / 2), suf = t.substr((l + 1) / 2, l / 2);
    reverse(all(pre));
    if (pre<=suf){
        if (l % 2 == 1)ans = add(ans, Val(s[l/2] + 1, s[l/2] + 1));
        else ans = add(ans, Val(1, 1));
    }

    cout << ans.first << endl << ans.second << endl;
}
0