#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define sz(s) (int)s.size()
#define bit(i, j) ((j >> i) & 1)
#define all(v) v.begin(), v.end()
#define taskname "file"
typedef long long ll;
int a, b, dp[19][11][11][2][2];
vector <int> v;
void cs(int x){
while (x){
v.push_back(x % 10);
x /= 10;
}
reverse(all(v));
}
int get(int x){
if (x <= 9) return 0;
v.clear();
cs(x);
for (int cs = 1; cs <= sz(v); ++cs)
for (int i = 0; i <= 10; ++i)
for (int j = 0; j <= 10; ++j)
for (int k = 0; k < 2; ++k)
for (int l = 0; l < 2; ++l)
dp[cs][i][j][k][l] = 0;
for (int i = 0; i < 10; ++i)
if (i <= v[0]) dp[1][(!i ? 10 : i)][10][i == v[0]][0] = 1;
else break;
for (int cs = 1; cs < sz(v); ++cs)
for (int i = 0; i <= 10; ++i)
for (int j = 0; j <= 10; ++j)
for (int k = 0; k < 2; ++k)
for (int l = 0; l < 2; ++l){
if (!dp[cs][i][j][k][l]) continue;
for (int nxt = 0; nxt <= (k ? v[cs] : 9); ++nxt){
if (i == 10 && !nxt) dp[cs + 1][10][10][0][0] = 1;
else{
int l1 = l | (nxt == i) | (cs > 1 && nxt == j);
dp[cs + 1][nxt][i][k & (nxt == v[cs])][l1] += dp[cs][i][j][k][l];
}
}
}
int ans = 0;
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 10; ++j)
for (int k = 0; k < 2; ++k)
ans += dp[sz(v)][i][j][k][1];
return ans;
}
void solve(){
cin >> a >> b;
cout << b - a + 1 - get(b) + get(a - 1);
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen(taskname".inp", "r", stdin);
// freopen(taskname".out", "w", stdout);
int tt = 1;
// cin >> tt;
while (tt--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |