結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | kei |
提出日時 | 2018-10-08 22:07:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 176 ms / 2,000 ms |
コード長 | 5,496 bytes |
コンパイル時間 | 1,689 ms |
コンパイル使用メモリ | 175,896 KB |
実行使用メモリ | 13,568 KB |
最終ジャッジ日時 | 2024-10-12 15:55:05 |
合計ジャッジ時間 | 6,838 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 25 ms
5,248 KB |
testcase_01 | AC | 29 ms
5,248 KB |
testcase_02 | AC | 36 ms
8,320 KB |
testcase_03 | AC | 38 ms
9,856 KB |
testcase_04 | AC | 42 ms
11,392 KB |
testcase_05 | AC | 38 ms
7,936 KB |
testcase_06 | AC | 39 ms
9,600 KB |
testcase_07 | AC | 38 ms
8,064 KB |
testcase_08 | AC | 47 ms
13,184 KB |
testcase_09 | AC | 45 ms
13,184 KB |
testcase_10 | AC | 46 ms
13,184 KB |
testcase_11 | AC | 45 ms
13,184 KB |
testcase_12 | AC | 78 ms
13,312 KB |
testcase_13 | AC | 78 ms
13,312 KB |
testcase_14 | AC | 110 ms
13,440 KB |
testcase_15 | AC | 113 ms
13,312 KB |
testcase_16 | AC | 111 ms
13,440 KB |
testcase_17 | AC | 110 ms
13,440 KB |
testcase_18 | AC | 81 ms
13,312 KB |
testcase_19 | AC | 79 ms
13,184 KB |
testcase_20 | AC | 77 ms
13,312 KB |
testcase_21 | AC | 83 ms
13,184 KB |
testcase_22 | AC | 110 ms
13,440 KB |
testcase_23 | AC | 113 ms
13,440 KB |
testcase_24 | AC | 109 ms
13,568 KB |
testcase_25 | AC | 109 ms
13,440 KB |
testcase_26 | AC | 109 ms
13,440 KB |
testcase_27 | AC | 109 ms
13,312 KB |
testcase_28 | AC | 105 ms
13,312 KB |
testcase_29 | AC | 165 ms
13,440 KB |
testcase_30 | AC | 167 ms
13,568 KB |
testcase_31 | AC | 168 ms
13,568 KB |
testcase_32 | AC | 171 ms
13,440 KB |
testcase_33 | AC | 111 ms
13,312 KB |
testcase_34 | AC | 158 ms
13,312 KB |
testcase_35 | AC | 176 ms
13,440 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; } template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; } template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; } template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; } /* <url:https://yukicoder.me/problems/no/315> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ const ll MOD = 1e9+7; ll dpA[2][3][2][2][100000]; // i桁目,桁和j,3を含むか否か,確実にA以下か,直近3桁 ll dpB[2][3][2][2][100000]; ll solve(){ ll res = 0; string A,B; cin >> A >> B; ll P; cin >> P; int curA = 0,nextA = 1; for(auto& c:A) c -= '0'; dpA[curA][0][0][0][0] = 1; for(int i = 0; i < A.length();i++){ for(int j = 0; j < 3;j++){ for(int k = 0; k < 2;k++){ for(int l = 0; l < 2;l++){ if(i < (int)A.length()-5){ int m = 0; if(dpA[curA][j][k][l][m] == 0) continue; int lim = l ? 9 : A[i]; for(int d = 0; d <= lim;d++){ (dpA[nextA][(j+d)%3][k||(d==3)][l||(d < lim)][m] += dpA[curA][j][k][l][m])%=MOD; } dpA[curA][j][k][l][m] = 0; }else{ for(int m = 0; m < 100000;m++){ if(dpA[curA][j][k][l][m] == 0) continue; int lim = l ? 9 : A[i]; for(int d = 0; d <= lim;d++){ (dpA[nextA][(j+d)%3][k||(d==3)][l||(d < lim)][m%10000*10+d] += dpA[curA][j][k][l][m])%=MOD; } dpA[curA][j][k][l][m] = 0; } } } } } swap(curA,nextA); } int curB = 0,nextB = 1; for(auto& c:B) c -= '0'; dpB[curB][0][0][0][0] = 1; for(int i = 0; i < B.length();i++){ for(int j = 0; j < 3;j++){ for(int k = 0; k < 2;k++){ for(int l = 0; l < 2;l++){ if(i < (int)B.length()-5){ int m = 0; if(dpB[curB][j][k][l][m] == 0) continue; int lim = l ? 9 : B[i]; for(int d = 0; d <= lim;d++){ (dpB[nextB][(j+d)%3][k||(d==3)][l||(d < lim)][m] += dpB[curB][j][k][l][m])%=MOD; } dpB[curB][j][k][l][m] = 0; }else{ for(int m = 0; m < 100000;m++){ if(dpB[curB][j][k][l][m] == 0) continue; int lim = l ? 9 : B[i]; for(int d = 0; d <= lim;d++){ (dpB[nextB][(j+d)%3][k||(d==3)][l||(d < lim)][m%10000*10+d] += dpB[curB][j][k][l][m])%=MOD; } dpB[curB][j][k][l][m] = 0; } } } } } swap(curB,nextB); } bool flag = false; if(accumulate(A.begin(),A.end(),0LL)%3==0||count(A.begin(),A.end(),3)!=0){ ll thdigit = 0; for(int i = 0; i < A.length();i++){ thdigit = thdigit*10 + A[i]; thdigit%=100000; } if(thdigit%P!=0){ flag = true; } } ll sumA = 0; for(int j = 0; j < 3;j++){ for(int k = 0; k < 2;k++){ for(int l = 0; l < 2;l++){ for(int m = 0; m < 100000;m++){ if(j==0 || k == 1){ if(m%P!=0){ (sumA+=dpA[curA][j][k][l][m])%=MOD; } } } } } } ll sumB = 0; for(int j = 0; j < 3;j++){ for(int k = 0; k < 2;k++){ for(int l = 0; l < 2;l++){ for(int m = 0; m < 100000;m++){ if(j==0 || k == 1){ if(m%P!=0){ (sumB+=dpB[curB][j][k][l][m])%=MOD; } } } } } } res = (sumB - sumA + MOD)%MOD; (res += flag)%=MOD; return res; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); cout << solve() << endl; return 0; }