結果
問題 | No.260 世界のなんとか3 |
ユーザー | pekempey |
提出日時 | 2019-12-24 10:19:56 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 4,252 bytes |
コンパイル時間 | 2,487 ms |
コンパイル使用メモリ | 212,840 KB |
実行使用メモリ | 203,648 KB |
最終ジャッジ日時 | 2024-09-21 15:34:43 |
合計ジャッジ時間 | 42,901 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | MLE | - |
testcase_01 | MLE | - |
testcase_02 | MLE | - |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | MLE | - |
testcase_06 | MLE | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | MLE | - |
testcase_10 | MLE | - |
testcase_11 | TLE | - |
testcase_12 | MLE | - |
testcase_13 | MLE | - |
testcase_14 | MLE | - |
testcase_15 | MLE | - |
testcase_16 | MLE | - |
testcase_17 | MLE | - |
testcase_18 | MLE | - |
testcase_19 | TLE | - |
testcase_20 | MLE | - |
testcase_21 | MLE | - |
testcase_22 | MLE | - |
testcase_23 | MLE | - |
testcase_24 | MLE | - |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | MLE | - |
testcase_28 | MLE | - |
testcase_29 | MLE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; struct node { int k; int ch[10] = {}; }; node nodes[3000000]; int ptr = 2; int create() { return ptr++; } int complement(int x) { if (x == 0) return 1; if (x == 1) return 0; static map<int, int> memo; if (memo.count(x)) return memo[x]; int res = create(); for (int i = 0; i < 10; i++) { nodes[res].ch[i] = complement(nodes[x].ch[i]); } return memo[x] = res; } int cup(int x, int y) { if (x == 1 || y == 1) return 1; if (x == 0) return y; if (y == 0) return x; static map<pair<int, int>, int> memo; pair<int, int> key(x, y); if (memo.count(key)) return memo[key]; int res = create(); for (int i = 0; i < 10; i++) { nodes[res].ch[i] = cup(nodes[x].ch[i], nodes[y].ch[i]); } return memo[key] = res; } int cap(int x, int y) { if (x == 0 || y == 0) return 0; if (x == 1) return y; if (y == 1) return x; static map<pair<int, int>, int> memo; pair<int, int> key(x, y); if (memo.count(key)) return memo[key]; int res = create(); for (int i = 0; i < 10; i++) { nodes[res].ch[i] = cap(nodes[x].ch[i], nodes[y].ch[i]); } return memo[key] = res; } constexpr int MOD = 1000000007; class mint { int n; public: mint(int n_ = 0) : n(n_) {} explicit operator int() { return n; } friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); } friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; } friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; } friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; } friend mint &operator+=(mint &a, mint b) { return a = a + b; } friend mint &operator-=(mint &a, mint b) { return a = a - b; } friend mint &operator*=(mint &a, mint b) { return a = a * b; } friend bool operator==(mint a, mint b) { return a.n == b.n; } friend bool operator!=(mint a, mint b) { return a.n != b.n; } friend istream &operator>>(istream &i, mint &a) { return i >> a.n; } friend ostream &operator<<(ostream &o, mint a) { return o << a.n; } }; mint count(int x) { if (x == 0) return 0; if (x == 1) return 1; static map<int, mint> memo; if (memo.count(x)) return memo[x]; mint res = 0; for (int i = 0; i < 10; i++) { res += count(nodes[x].ch[i]); } return memo[x] = res; } // ------------------------- int LE(string &s, int k = 0, int lt = 0) { if (k == s.size()) return 1; static map<tuple<int, int>, int> memo; tuple<int, int> key(k, lt); if (memo.count(key)) return memo[key]; int res = create(); for (int i = 0; i < 10; i++) { if (lt == 1 || i <= s[k] - '0') { nodes[res].ch[i] = LE(s, k + 1, lt || (i < s[k] - '0')); } } return memo[key] = res; } int GE(string &s, int k = 0, int gt = 0) { if (k == s.size()) return 1; static map<tuple<int, int>, int> memo; tuple<int, int> key(k, gt); if (memo.count(key)) return memo[key]; int res = create(); for (int i = 0; i < 10; i++) { if (gt == 1 || i >= s[k] - '0') { nodes[res].ch[i] = GE(s, k + 1, gt || (i > s[k] - '0')); } } return memo[key] = res; } int MULT(int n, int m, int k = 0, int md = 0) { if (k == n) return md == 0; static map<tuple<int, int, int, int>, int> memo; tuple<int, int, int, int> key(n, m, k, md); if (memo.count(key)) return memo[key]; int res = create(); for (int i = 0; i < 10; i++) { nodes[res].ch[i] = MULT(n, m, k + 1, (md * 10 + i) % m); } return memo[key] = res; } int HAS(int n, int m, int k = 0) { if (k == n) return 0; static map<tuple<int, int, int>, int> memo; tuple<int, int, int> key(n, m, k); if (memo.count(key)) return memo[key]; int res = create(); for (int i = 0; i < 10; i++) { if (i == m) { nodes[res].ch[i] = 1; } else { nodes[res].ch[i] = HAS(n, m, k + 1); } } return memo[key] = res; } int main() { string A, B; cin >> A >> B; if (A.size() < B.size()) A = string(B.size() - A.size(), '0') + A; int n = A.size(); int le = LE(B); int ge = GE(A); int range = cap(ge, le); int aho = cup(HAS(n, 3), MULT(n, 3)); int seisyun = MULT(n, 8); int ans = cap(range, cap(aho, complement(seisyun))); cout << count(ans) << endl; }