結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | is_eri23 |
提出日時 | 2015-12-08 17:12:29 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,396 bytes |
コンパイル時間 | 1,512 ms |
コンパイル使用メモリ | 160,532 KB |
実行使用メモリ | 256,928 KB |
最終ジャッジ日時 | 2024-09-14 20:19:32 |
合計ジャッジ時間 | 39,894 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 180 ms
228,228 KB |
testcase_01 | AC | 179 ms
228,352 KB |
testcase_02 | AC | 183 ms
228,352 KB |
testcase_03 | AC | 181 ms
228,344 KB |
testcase_04 | AC | 181 ms
228,352 KB |
testcase_05 | AC | 182 ms
228,316 KB |
testcase_06 | AC | 183 ms
228,352 KB |
testcase_07 | AC | 181 ms
228,352 KB |
testcase_08 | AC | 180 ms
228,340 KB |
testcase_09 | AC | 182 ms
228,352 KB |
testcase_10 | AC | 181 ms
228,224 KB |
testcase_11 | AC | 181 ms
228,352 KB |
testcase_12 | AC | 741 ms
242,656 KB |
testcase_13 | AC | 759 ms
242,688 KB |
testcase_14 | AC | 1,292 ms
242,616 KB |
testcase_15 | AC | 1,302 ms
242,616 KB |
testcase_16 | AC | 1,302 ms
242,560 KB |
testcase_17 | AC | 1,283 ms
242,620 KB |
testcase_18 | AC | 743 ms
242,484 KB |
testcase_19 | AC | 743 ms
242,500 KB |
testcase_20 | AC | 744 ms
242,580 KB |
testcase_21 | AC | 745 ms
242,644 KB |
testcase_22 | AC | 1,283 ms
242,616 KB |
testcase_23 | AC | 1,282 ms
242,616 KB |
testcase_24 | AC | 1,281 ms
242,620 KB |
testcase_25 | AC | 1,280 ms
242,616 KB |
testcase_26 | AC | 1,294 ms
242,616 KB |
testcase_27 | AC | 1,277 ms
242,552 KB |
testcase_28 | AC | 1,267 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 N; int dp_go(int now, int mod8, int mod3, bool in3, bool under, int last2){ if (now == N) { 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 && N - now == 2) { if (mod8 == 0 && i == 0) { last2 += 1; } }else if (N - now == 1) { if (mod8 == 0 && i == 0) { last2 += 1; } } if (i != 3) { ret += dp_go(now+1, ((mod8*10 + i) & 7), (mod3 * 10 + i) % 3, in3, true, last2); }else{ ret += dp_go(now+1, ((mod8*10 + i) & 7), (mod3 * 10 + i) % 3, true, true, last2); } if (ret >= MOD) { ret -= MOD; } if (N - now <= 2) { last2 = tmp; } } }else{ int up = S[now] - '0'; for (int i = 0; i <= up; i++) { int tmp = last2; if (P == 800 && N - now == 2) { if (mod8 == 0 && i == 0) { last2 += 1; } }else if (N - now == 1) { if (mod8 == 0 && i == 0) { last2 += 1; } } if (i != 3) { ret += dp_go(now+1, ((mod8*10 + i) & 7), (mod3 * 10 + i) % 3, in3, i < up, last2); }else{ ret += dp_go(now+1, ((mod8*10 + i) & 7), (mod3 * 10 + i) % 3, true, i < up, last2); } if (ret >= MOD) { ret -= MOD; } if (N - 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); swap(S,B); N = sz(S); ll ansB = dp_go(0,0,0,false,false,0); mem(memo,-1); swap(S,A); N = sz(S); ll ansA = dp_go(0,0,0,false,false,0); cout << (((ansB - ansA) % MOD) + MOD) % MOD << endl; return 0; } inline 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; } } }