結果
問題 | No.1086 桁和の桁和2 |
ユーザー |
![]() |
提出日時 | 2020-06-19 22:14:29 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 263 ms / 3,000 ms |
コード長 | 2,114 bytes |
コンパイル時間 | 886 ms |
コンパイル使用メモリ | 80,212 KB |
実行使用メモリ | 12,672 KB |
最終ジャッジ日時 | 2024-07-22 17:41:18 |
合計ジャッジ時間 | 6,190 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 31 |
ソースコード
#include <iostream>#include <cstdio>#include <cmath>#include <ctime>#include <cstdlib>#include <cassert>#include <vector>#include <list>#include <stack>#include <queue>#include <deque>#include <map>#include <set>#include <bitset>#include <string>#include <algorithm>#include <utility>#define llint long long#define inf 1e18#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)#define chmin(x, y) (x) = min((x), (y))#define chmax(x, y) (x) = max((x), (y))#define mod 1000000007using namespace std;typedef pair<llint, llint> P;llint n;llint l[100005], r[100005], d[100005];llint dp[100005][9];llint inv9;llint modpow(llint a, llint n){if(n == 0) return 1;if(n % 2){return ((a%mod) * (modpow(a, n-1)%mod)) % mod;}else{return modpow((a*a)%mod, n/2) % mod;}}llint get(llint k){llint ret = modpow(10, k+1);ret += mod-1, ret %= mod;ret *= inv9, ret %= mod;return ret;}llint calc(llint l, llint r){llint ret = get(r-1) + mod - get(l-1);ret %= mod;return ret;}int main(void){ios::sync_with_stdio(0);cin.tie(0);inv9 = modpow(9, mod-2);cin >> n;for(int i = 1; i <= n; i++) cin >> l[i];for(int i = 1; i <= n; i++) cin >> r[i];for(int i = 1; i <= n; i++) cin >> d[i];for(int i = 1; i <= n-1; i++){if(d[i] > 0 && d[i+1] == 0){cout << 0 << endl;return 0;}}llint pos = 0;for(int i = n; i >= 1; i--){if(d[i] == 0){pos = i;break;}}dp[pos][0] = 1;for(int i = pos; i < n; i++){llint mul = calc(l[i+1], r[i+1]);//cout << i+1 << " " << mul << endl;for(int j = 0; j < 9; j++){for(int k = 0; k < 9; k++){llint nj = (j+k)%9;if(nj != d[i+1]%9) continue;(dp[i+1][nj] += dp[i][j] * mul % mod) %= mod;}if(i > pos && d[i+1]%9 == j) (dp[i+1][j] += dp[i][j]) %= mod;}}/*for(int i = 0; i <= n; i++){for(int j = 0; j < 9; j++){cout << dp[i][j] << " ";}cout << endl;}*/llint ans = 0;for(int i = 0; i < 9; i++) ans += dp[n][i], ans %= mod;cout << ans << endl;return 0;}