結果

問題 No.528 10^9と10^9+7と回文
ユーザー imulanimulan
提出日時 2017-06-10 02:22:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 1,000 ms
コード長 1,290 bytes
コンパイル時間 1,493 ms
コンパイル使用メモリ 165,936 KB
実行使用メモリ 9,952 KB
最終ジャッジ日時 2023-10-01 00:57:00
合計ジャッジ時間 3,119 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,708 KB
testcase_01 AC 6 ms
5,680 KB
testcase_02 AC 7 ms
5,640 KB
testcase_03 AC 7 ms
5,696 KB
testcase_04 AC 6 ms
5,644 KB
testcase_05 AC 7 ms
5,640 KB
testcase_06 AC 7 ms
5,752 KB
testcase_07 AC 6 ms
5,704 KB
testcase_08 AC 7 ms
5,680 KB
testcase_09 AC 7 ms
5,708 KB
testcase_10 AC 42 ms
9,892 KB
testcase_11 AC 43 ms
9,784 KB
testcase_12 AC 42 ms
9,760 KB
testcase_13 AC 42 ms
9,952 KB
testcase_14 AC 27 ms
8,280 KB
testcase_15 AC 25 ms
7,920 KB
testcase_16 AC 24 ms
7,708 KB
testcase_17 AC 21 ms
7,340 KB
testcase_18 AC 41 ms
9,592 KB
testcase_19 AC 16 ms
6,788 KB
testcase_20 AC 31 ms
8,528 KB
testcase_21 AC 21 ms
7,296 KB
testcase_22 AC 6 ms
5,640 KB
testcase_23 AC 6 ms
5,696 KB
testcase_24 AC 7 ms
5,788 KB
testcase_25 AC 10 ms
6,124 KB
testcase_26 AC 43 ms
9,892 KB
testcase_27 AC 17 ms
9,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int PW = 100001;
ll pw[PW];

string n;
int N;
ll mod;

ll dp[PW][2];
ll dfs(int d, int s)
{
    if(d == (N+1)/2) return s;
    if(dp[d][s]>=0) return dp[d][s];

    ll ret = 0;

    int l=0;
    if(d==0) l=1;

    int r=9;
    if(s==0) r=n[d]-'0';

    for(int i=l; i<=r; ++i) (ret += dfs(d+1,s|(i<n[d]-'0')))%=mod;

    return dp[d][s] = ret;
}

ll solve()
{
    pw[0]=1;
    for(int i=1; i<PW; ++i) pw[i] = (pw[i-1]*10)%mod;

    ll ans = 0;
    for(int i=1; i<N; ++i) (ans+=9*pw[(i-1)/2])%=mod;

    memset(dp,-1,sizeof(dp));
    ans += dfs(0,0);

    string s=n;
    rep(i,(N+1)/2) s[N-1-i] = s[i];
    ans += (s<=n);

    return ans%mod;
}

int main()
{
    cin >>n;
    N = n.size();

    mod = 1e9;
    cout << solve() << endl;
    mod += 7;
    cout << solve() << endl;
    return 0;
}
0