結果
問題 |
No.1086 桁和の桁和2
|
ユーザー |
|
提出日時 | 2020-06-19 22:36:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 130 ms / 3,000 ms |
コード長 | 1,001 bytes |
コンパイル時間 | 2,462 ms |
コンパイル使用メモリ | 194,836 KB |
最終ジャッジ日時 | 2025-01-11 07:11:01 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h> using namespace std; constexpr int mod = 1000000007; long long modpow(long long a, long long r) { long long ret = 1; while (r) { if (r & 1) ret = ret * a % mod; r >>= 1; a = a * a % mod; } return ret; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; vector<long long> L(N), R(N), D(N); for (auto &x: L) cin >> x; for (auto &x: R) cin >> x; for (auto &x: D) cin >> x; int Dc = 0; long long Ans = 1; long long inv9 = modpow(9, mod-2); for (int i = 0; i < N && Ans; i++) { if (D[i] == 0) { if (Dc != 0) Ans = 0; continue; } int Diff = (D[i] - Dc + 9) % 9; long long U = (modpow(10, R[i]) - modpow(10, L[i]) + mod) % mod * inv9 % mod; U = (U % mod + mod) % mod; if (Diff == 0 && Dc != 0) U++; Dc = D[i]; Ans = Ans * U % mod; } cout << Ans << "\n"; return 0; }