結果
| 問題 |
No.528 10^9と10^9+7と回文
|
| ユーザー |
|
| 提出日時 | 2017-06-10 00:16:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,527 bytes |
| コンパイル時間 | 1,965 ms |
| コンパイル使用メモリ | 169,452 KB |
| 実行使用メモリ | 12,356 KB |
| 最終ジャッジ日時 | 2024-09-22 20:51:19 |
| 合計ジャッジ時間 | 3,290 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 WA * 9 |
ソースコード
#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][2];
ll dfs(int d, int s, int f)
{
if(d == (N+1)/2)
{
if(f==1 && s==0) return 0;
else return 1;
}
if(dp[d][s][f]>=0) return dp[d][s][f];
ll ret = 0;
int l=0;
if(d==0) l=1;
int r=9;
if(s==0) r=n[d]-'0';
// printf(" (%d,%d,%d) %d ~ %d\n", d,s,f,l,r);
for(int i=l; i<=r; ++i)
{
if(s==0)
{
int nf = 0;
if(i>n[N-1-d]-'0') nf=1;
ret += dfs(d+1,s|(i<n[d]-'0'),f|nf);
}
else ret += dfs(d+1,1,f);
ret %= mod;
}
return dp[d][s][f] = 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,0);
return ans%mod;
}
int main()
{
cin >>n;
N = n.size();
mod = 1e9;
cout << solve() << endl;
mod += 7;
cout << solve() << endl;
return 0;
}