結果

問題 No.528 10^9と10^9+7と回文
ユーザー TangentDayTangentDay
提出日時 2017-06-09 23:39:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,781 bytes
コンパイル時間 859 ms
コンパイル使用メモリ 83,204 KB
実行使用メモリ 6,532 KB
最終ジャッジ日時 2023-10-24 02:27:46
合計ジャッジ時間 1,966 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,712 KB
testcase_01 AC 2 ms
5,712 KB
testcase_02 AC 2 ms
5,712 KB
testcase_03 AC 2 ms
5,712 KB
testcase_04 AC 2 ms
5,712 KB
testcase_05 AC 2 ms
5,712 KB
testcase_06 AC 2 ms
5,712 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
5,712 KB
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 AC 2 ms
5,712 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 24 ms
6,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) c.begin(), c.end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll mod1 = 1e9, mod2 = 1e9 + 7;

ll dp1[100010][2], dp2[100010][2];

ll powll(ll x, ll y, ll m){
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= m;
        x = (x*x) % m;
        y >>= 1LL;
    }
    return res;
}

int main() {
    string s;
    cin >> s;
    int n = s.length();
    ll ans1 = 0, ans2 = 0;
    FOR(i,1,n-1){
        ans1 = (ans1 + 9 * powll(10, (i+1)/2-1, mod1)) % mod1;
        ans2 = (ans2 + 9 * powll(10, (i+1)/2-1, mod2)) % mod2;
    }

    dp1[0][0] = 1;
    dp2[0][0] = 1;
    REP(i,(n+1)/2) REP(j,2){
        if (j == 1){
            REP(k,10){
                (dp1[i+1][1] += dp1[i][1]) %= mod1;
                (dp2[i+1][1] += dp2[i][1]) %= mod2;
            }
        }else{
            int l = (i == 0 ? 1 : 0);
            int r = min(s[i] - '0', s[n-1-i] - '0');
            int lim = s[i] - '0';
            FOR(k,l,r){
                (dp1[i+1][j || k < lim] += dp1[i][j]) %= mod1;
                (dp2[i+1][j || k < lim] += dp2[i][j]) %= mod2;
            }
        }
    }

    int m = (n+1)/2;
    ans1 = (ans1 + dp1[m][0] + dp1[m][1]) % mod1;
    ans2 = (ans2 + dp2[m][0] + dp2[m][1]) % mod2;

    cout << ans1 << endl << ans2 << endl;
}
0