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;
#define int long long
int a, b, arr[19], dp[19][10][10][2][2];
int calc (int pos, int las1, int las2, bool smaller, bool nonZero) {
if ( (nonZero || las1) && las1 == las2) return 0;
if (pos == 1) {
if (smaller || las1 < arr[pos] || (las1 == arr[pos] && las2 <= arr[pos - 1]) ) return 1;
}
int &ret = dp[pos][las1][las2][smaller][nonZero];
if (ret != -1) return ret;
ret = 0;
if (smaller || las1 < arr[pos] || (las1 == arr[pos] && las2 <= arr[pos - 1]) ) {
for (int las3 = 0; las3 < 10; ++las3) {
if ( (nonZero || las1) && las1 == las3) continue ;
ret += calc(pos - 1, las2, las3, max(smaller, (las1 < arr[pos]) ), max(nonZero, (las1 > 0) ) );
}
}
return ret;
}
int solve (int lim) {
memset(dp, -1, sizeof dp);
if (lim < 0) return 0;
int cur = 0;
memset(arr, 0, sizeof arr);
while (lim) {
arr[cur++] = lim % 10; lim /= 10;
}
int ret = 0;
for (int i = 0; i < 10; ++i) {
for (int j = 0; j < 10; ++j) {
ret += calc(18, i, j, 0, 0);
}
}
return ret;
}
signed main () {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> a >> b;
cout << solve(b) - solve(a - 1);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |