結果
| 問題 |
No.528 10^9と10^9+7と回文
|
| ユーザー |
TangentDay
|
| 提出日時 | 2017-06-09 23:39:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,781 bytes |
| コンパイル時間 | 763 ms |
| コンパイル使用メモリ | 81,824 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 19:23:18 |
| 合計ジャッジ時間 | 1,769 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 18 |
ソースコード
#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;
}
TangentDay