結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | is_eri23 |
提出日時 | 2015-12-08 17:03:43 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,391 bytes |
コンパイル時間 | 1,446 ms |
コンパイル使用メモリ | 159,996 KB |
実行使用メモリ | 257,024 KB |
最終ジャッジ日時 | 2024-09-14 20:18:14 |
合計ジャッジ時間 | 38,463 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 203 ms
228,352 KB |
testcase_01 | AC | 203 ms
228,224 KB |
testcase_02 | AC | 202 ms
228,224 KB |
testcase_03 | AC | 202 ms
228,352 KB |
testcase_04 | AC | 202 ms
228,352 KB |
testcase_05 | AC | 200 ms
228,352 KB |
testcase_06 | AC | 202 ms
228,352 KB |
testcase_07 | AC | 203 ms
228,352 KB |
testcase_08 | AC | 205 ms
228,352 KB |
testcase_09 | AC | 205 ms
228,224 KB |
testcase_10 | AC | 203 ms
228,224 KB |
testcase_11 | AC | 204 ms
228,352 KB |
testcase_12 | AC | 728 ms
242,688 KB |
testcase_13 | AC | 727 ms
242,560 KB |
testcase_14 | AC | 1,241 ms
242,616 KB |
testcase_15 | AC | 1,241 ms
242,616 KB |
testcase_16 | AC | 1,236 ms
242,620 KB |
testcase_17 | AC | 1,242 ms
242,560 KB |
testcase_18 | AC | 730 ms
242,432 KB |
testcase_19 | AC | 735 ms
242,560 KB |
testcase_20 | AC | 743 ms
242,688 KB |
testcase_21 | AC | 745 ms
242,688 KB |
testcase_22 | AC | 1,263 ms
242,684 KB |
testcase_23 | AC | 1,260 ms
242,688 KB |
testcase_24 | AC | 1,237 ms
242,616 KB |
testcase_25 | AC | 1,267 ms
242,616 KB |
testcase_26 | AC | 1,240 ms
242,620 KB |
testcase_27 | AC | 1,245 ms
242,616 KB |
testcase_28 | AC | 1,249 ms
242,616 KB |
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; int memo[200010][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; int 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); } if (ret >= MOD) { 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); } if (ret >= MOD) { ret -= MOD; } if (sz(S) - now <= 2) { last2 = tmp; } } } return memo[now][mod8][mod3][in3][under][last2] = (int) 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; ll ansB = dp_go(0,0,0,false,false,0); mem(memo,-1); S = A; ll 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; } } }