結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | is_eri23 |
提出日時 | 2015-12-08 16:59:13 |
言語 | C++11 (gcc 11.4.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 4,319 bytes |
コンパイル時間 | 1,464 ms |
コンパイル使用メモリ | 160,132 KB |
実行使用メモリ | 482,304 KB |
最終ジャッジ日時 | 2024-09-14 20:15:55 |
合計ジャッジ時間 | 51,091 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | MLE | - |
testcase_01 | MLE | - |
testcase_02 | MLE | - |
testcase_03 | MLE | - |
testcase_04 | MLE | - |
testcase_05 | MLE | - |
testcase_06 | MLE | - |
testcase_07 | MLE | - |
testcase_08 | MLE | - |
testcase_09 | MLE | - |
testcase_10 | MLE | - |
testcase_11 | MLE | - |
testcase_12 | MLE | - |
testcase_13 | MLE | - |
testcase_14 | MLE | - |
testcase_15 | MLE | - |
testcase_16 | MLE | - |
testcase_17 | MLE | - |
testcase_18 | MLE | - |
testcase_19 | MLE | - |
testcase_20 | MLE | - |
testcase_21 | MLE | - |
testcase_22 | MLE | - |
testcase_23 | MLE | - |
testcase_24 | MLE | - |
testcase_25 | MLE | - |
testcase_26 | MLE | - |
testcase_27 | MLE | - |
testcase_28 | MLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | MLE | - |
testcase_34 | TLE | - |
testcase_35 | MLE | - |
ソースコード
#include <bits/stdc++.h> #define EPS 1e-9 #define INF 1070000000LL #define MOD 1000000007LL #define fir first #define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++) #define numa(x,a) for(auto x: a) #define ite iterator #define mp make_pair #define rep(i,n) rep2(i,0,n) #define rep2(i,m,n) for(int i=m;i<(n);i++) #define pb push_back #define pf push_front #define sec second #define sz(x) ((int)(x).size()) #define ALL( c ) (c).begin(), (c).end() #define gcd(a,b) __gcd(a,b) #define mem(x,n) memset(x,n,sizeof(x)) #define endl "\n" using namespace std; template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){} template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); } template <class T,class U> std::ostream& operator<<(std::ostream &os, std::pair<T,U> &p){ os << "(" << p.first <<", " << p.second <<")";return os; } template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; } template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; } template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; } #define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; } #define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); } #define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); } #define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); } using ll = long long; ll memo[200100][8][3][2][2][3];//now, mod8, mod3, in3, under, last2(00,01,10,11) 8->0->0 string S; string A,B; int P; ll dp_go(int now, int mod8, int mod3, bool in3, bool under, int last2){ if (now == sz(S)) { if (mod3 == 0 || in3) { if (P == 8) { return !(mod8 == 0); }else if (P == 80) { return !(last2 >= 1); }else if (P == 800) { return !(last2 >= 2); } } return 0; } if (memo[now][mod8][mod3][in3][under][last2] >= 0) { return memo[now][mod8][mod3][in3][under][last2]; } ll ret = 0; if (under) { for (int i = 0; i <= 9; i++) { int tmp = last2; if (P == 800 && sz(S) - now == 2) { if (mod8 == 0 && i == 0) { last2 += 1; } }else if (sz(S) - now == 1) { if (mod8 == 0 && i == 0) { last2 += 1; } } if (i != 3) { ret += dp_go(now+1, (mod8*10 + i) % 8, (mod3 * 10 + i) % 3, in3, true, last2); }else{ ret += dp_go(now+1, (mod8*10 + i) % 8, (mod3 * 10 + i) % 3, true, true, last2); } ret %= MOD; if (sz(S) - now <= 2) { last2 = tmp; } } }else{ int up = S[now] - '0'; for (int i = 0; i <= up; i++) { int tmp = last2; if (P == 800 && sz(S) - now == 2) { if (mod8 == 0 && i == 0) { last2 += 1; } }else if (sz(S) - now == 1) { if (mod8 == 0 && i == 0) { last2 += 1; } } if (i != 3) { ret += dp_go(now+1, (mod8*10 + i) % 8, (mod3 * 10 + i) % 3, in3, i < up, last2); }else{ ret += dp_go(now+1, (mod8*10 + i) % 8, (mod3 * 10 + i) % 3, true, i < up, last2); } ret %= MOD; if (sz(S) - now <= 2) { last2 = tmp; } } } return memo[now][mod8][mod3][in3][under][last2] = ret; } void dec(string &a); int main() { cin.tie(0); ios_base::sync_with_stdio(0); mem(memo,-1); cin >> A >> B >> P; dec(A); S = B; auto ansB = dp_go(0,0,0,false,false,0); mem(memo,-1); S = A; auto ansA = dp_go(0,0,0,false,false,0); //DEBUG2(ansB,ansA); cout << (((ansB - ansA) % MOD) + MOD) % MOD << endl; return 0; } void dec(string &a){ for (int i = sz(a)-1; i >= 0; i--) { if (a[i] == '0') { a[i] = '9'; }else{ a[i] -= 1; break; } } }