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>
#define ll long long
using namespace std;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 2e5 + 100;
ll f[20][11][11][2][2];
string s;
ll dq(int id, int a, int b, int is, int mean) {
if (id == len(s))
return 1;
if (f[id][a][b][is][mean] != -1)
return f[id][a][b][is][mean];
ll ans = 0;
int lim = is ? 9 : s[id] - '0';
if (mean == 0) {
for (int i = 0; i <= lim; i++) {
if (i == 0) {
ans += dq(id + 1, a, b, 1, 0);
} else {
ans += dq(id + 1, b, i, is | (i < (s[id] - '0')), 1);
}
}
} else {
for (int i = 0; i <= lim; i++) {
if (i != a && i != b) {
ans += dq(id + 1, b, i, is | (i < (s[id] - '0')), 1);
}
}
}
return f[id][a][b][is][mean] = ans;
}
ll cal(ll a) {
s = to_string(a);
mem(f, -1);
return dq(0, 10, 10, 0, 0);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll a, b;
cin >> a >> b;
cout << cal(b) - cal(a - 1) << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |