This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
ll BA[20];
void init() {
BA[0] = 1;
FOR(i, 1, 20) BA[i] = BA[i - 1] * 8;
}
ll calc(string t, int k) {
int n = t.size();
FOR(i, 1, n) if (t[i] == t[i - 1]) return 0;
FOR(i, 2, n) if (t[i] == t[i - 2]) return 0;
if (k == 0) return 1;
if (t.size() >= 2) return BA[k];
return BA[k - 1] * 9;
}
ll f(ll x) {
vector<psi> v;
ll ans = 0;
if (x == 0) return 0;
if (x <= 10) return x;
string s = to_string(x);
FOR(i, 0, s.size() - 1) {
for (char j = '1'; j <= '9'; j++) v.push_back(mp(string(1, j), i));
}
for (char j = '1'; j < s[0]; j++) v.push_back(mp(string(1, j), (int) s.size() - 1));
FOR(i, 1, s.size()) {
for (char j = '0'; j < s[i]; j++) v.push_back(mp(s.substr(0, i) + string(1, j), (int) s.size() - i - 1));
}
debug(x);
for (auto [t, k] : v) debug(t, k);
for (auto [t, k] : v) ans += calc(t, k);
return ans;
}
void miku() {
ll a, b;
cin >> a >> b;
cout << f(b + 1) - f(a) << '\n';
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
init();
miku();
return 0;
}
Compilation message (stderr)
numbers.cpp: In function 'll f(ll)':
numbers.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
numbers.cpp:52:5: note: in expansion of macro 'debug'
52 | debug(x);
| ^~~~~
numbers.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
numbers.cpp:53:27: note: in expansion of macro 'debug'
53 | for (auto [t, k] : v) debug(t, k);
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |