結果
問題 | No.528 10^9と10^9+7と回文 |
ユーザー |
![]() |
提出日時 | 2017-06-10 00:07:58 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,339 bytes |
コンパイル時間 | 661 ms |
コンパイル使用メモリ | 83,600 KB |
実行使用メモリ | 7,208 KB |
最終ジャッジ日時 | 2024-09-22 20:37:03 |
合計ジャッジ時間 | 1,842 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 WA * 17 |
ソースコード
#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][3], dp2[100010][3]; 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; // } FOR(k,l,9){ if (k < lim){ (dp1[i+1][1] += dp1[i][0] + dp1[i][2]) %= mod1; (dp2[i+1][1] += dp2[i][0] + dp2[i][2]) %= mod2; }else if (k == lim && k <= s[n-1-i] - '0'){ (dp1[i+1][0] += dp1[i][0]) %= mod1; (dp2[i+1][0] += dp2[i][0]) %= mod2; }else if (k == lim){ (dp1[i+1][2] += dp1[i][0]) %= mod1; (dp2[i+1][2] += dp2[i][0]) %= 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; }