結果
問題 | No.1086 桁和の桁和2 |
ユーザー | yukudo |
提出日時 | 2020-06-19 23:49:14 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 153 ms / 3,000 ms |
コード長 | 2,435 bytes |
コンパイル時間 | 3,520 ms |
コンパイル使用メモリ | 169,300 KB |
実行使用メモリ | 14,456 KB |
最終ジャッジ日時 | 2023-09-30 00:00:26 |
合計ジャッジ時間 | 6,022 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
12,248 KB |
testcase_01 | AC | 4 ms
12,244 KB |
testcase_02 | AC | 4 ms
12,168 KB |
testcase_03 | AC | 4 ms
12,288 KB |
testcase_04 | AC | 5 ms
12,228 KB |
testcase_05 | AC | 146 ms
14,248 KB |
testcase_06 | AC | 5 ms
12,160 KB |
testcase_07 | AC | 4 ms
12,220 KB |
testcase_08 | AC | 4 ms
12,172 KB |
testcase_09 | AC | 4 ms
12,244 KB |
testcase_10 | AC | 91 ms
13,108 KB |
testcase_11 | AC | 27 ms
12,544 KB |
testcase_12 | AC | 8 ms
12,444 KB |
testcase_13 | AC | 115 ms
13,724 KB |
testcase_14 | AC | 72 ms
13,000 KB |
testcase_15 | AC | 21 ms
12,460 KB |
testcase_16 | AC | 104 ms
13,512 KB |
testcase_17 | AC | 13 ms
12,500 KB |
testcase_18 | AC | 144 ms
14,160 KB |
testcase_19 | AC | 122 ms
13,776 KB |
testcase_20 | AC | 20 ms
12,460 KB |
testcase_21 | AC | 111 ms
13,484 KB |
testcase_22 | AC | 153 ms
14,112 KB |
testcase_23 | AC | 93 ms
13,168 KB |
testcase_24 | AC | 65 ms
13,004 KB |
testcase_25 | AC | 128 ms
13,772 KB |
testcase_26 | AC | 104 ms
13,304 KB |
testcase_27 | AC | 76 ms
12,976 KB |
testcase_28 | AC | 64 ms
12,860 KB |
testcase_29 | AC | 75 ms
12,968 KB |
testcase_30 | AC | 152 ms
14,252 KB |
testcase_31 | AC | 153 ms
14,104 KB |
testcase_32 | AC | 150 ms
14,456 KB |
testcase_33 | AC | 150 ms
14,232 KB |
testcase_34 | AC | 153 ms
14,248 KB |
testcase_35 | AC | 152 ms
14,316 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";} template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;} template<class T>void chmin(T&a,const T&b){if(a>b)a=b;} template<class T>void chmax(T&a,const T&b){if(a<b)a=b;} ll nextLong() { ll x; scanf("%lld", &x); return x;} const ll MOD = ((ll)1e9)+7; ll mod_pow(ll a, ll b, ll p) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % p; a = (a * a) % p; b >>= 1; } return res; } ll mod_inv(ll a, ll p) { return mod_pow(a % p, p - 2, p); } ll ways(ll n) { ll res = mod_pow(10, n, MOD); res = (res - 1 + MOD) % MOD; res *= mod_inv(9, MOD); res %= MOD; return res; } vector<ll> ways(ll L, ll R) { ll l = ways(L); ll r = ways(R); vector<ll> w(10); for (int i = 1; i <= 9; i++) w[i] = ((r - l) % MOD + MOD) % MOD; w[0] = 1; return w; } const int MAX_N = 112345; ll dp[MAX_N][10]; int main2() { CLR(dp, 0); int N = nextLong(); vector<ll> L(N), R(N), D(N); REP(i, N) L[i] = nextLong(); REP(i, N) R[i] = nextLong(); REP(i, N) D[i] = nextLong(); dp[0][0] = 1; for (int i = 0; i < N; i++) { auto w = ways(L[i], R[i]); // cout << "w="; pv(ALL(w)); for (int j = 0; j < 10; j++) { if (dp[i][j] == 0) continue; for (int k = 0; k < 10; k++) { int nj = (j + k) % 9; if (nj == 0) { if (j == 0 && k == 0) nj = 0; else nj = 9; } (dp[i+1][nj] += (dp[i][j] * w[k]) % MOD) %= MOD; } } // for (int j = 0; j < 10; j++) {cout << dp[i+1][j] << " "; } cout << endl; for (int j = 0; j < 10; j++) { if (D[i] != j) dp[i+1][j] = 0; } } ll ans = 0; for (int j = 0; j < 10; j++){ ans += dp[N][j]; } cout << ans << endl; return 0; } int main() { // int L = 2; // int R = 4; // { // vector<int> v(10); // v[0] = 1; // for (int i = pow(10, L); i < pow(10, R); i++) { // int r = i % 9; // if (r == 0) r = 9; // ++v[r]; // } // pv(ALL(v)); // } // auto x = ways(L, R); // pv(ALL(x)); // return 0; #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }