結果

問題 No.528 10^9と10^9+7と回文
ユーザー mamekinmamekin
提出日時 2017-06-10 00:21:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,781 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 106,456 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 04:08:19
合計ジャッジ時間 2,403 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
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 12 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int solve(const string& s, int mod)
{
    int n = s.size();

    long long ans = 0;
    long long tmp = 9;
    for(int i=1; i<n; ++i){
        ans += tmp;
        ans %= mod;
        if(i % 2 == 0){
            tmp *= 10;
            tmp %= mod;
        }
    }

    vector<int> dp(4, 0);
    dp[2] = 1;
    for(int i=0; i<(n+1)/2; ++i){
        vector<int> nextDp(4, 0);
        for(int a=0; a<4; ++a){
            for(int x=0; x<=s[i]-'0'; ++x){
                if(i == 0 && x == 0)
                    continue;
                int b = a;
                if(x != s[i] - '0')
                    b &= ~2;
                if(x < s[n-1-i] - '0')
                    b &= ~1;
                else if(x > s[n-1-i] - '0')
                    b |= 1;
                nextDp[b] += dp[a];
                nextDp[b] %= mod;
            }
        }
        dp.swap(nextDp);
    }

    for(int i=0; i<3; ++i){
        ans += dp[i];
        ans %= mod;
    }
    return ans;
}

int solve(int n)
{
    int ans = 0;
    for(int i=1; i<=n; ++i){
        string s = to_string(i);
        string t = s;
        reverse(t.begin(), t.end());
        if(s == t)
            ++ ans;
    }
    return ans;
}

int main()
{
    string s;
    cin >> s;

    cout << solve(s, 1000000000) << endl
         << solve(s, 1000000007) << endl;

    return 0;
}
0