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;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
ll dp[20][2][11][11][2];
void reset() {
memset(dp,-1,sizeof(dp));
}
ll solve(string s, int i, bool lower, int l0, int l1, bool started) {
int n = s.length();
if (i == n) {
return 1;
} else {
ll &res = dp[i][lower][l0][l1][started];
if (~res) return res;
res = 0;
for (int d=0; d<=(lower?9:int(s[i]-'0')); d++) {
if (d==l0) continue;
if (d==l1) continue;
res += solve(s,i+1,lower||(d<int(s[i]-'0')), l1, d, started || (d>0));
}
return res;
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll a,b;
cin>>a>>b;
// [a,b]
reset();
ll res = solve(to_string(b),0,false,10,10,false);
reset();
if (a>=0) {
res -= solve(to_string(a-1),0,false,10,10,false);
}
out(res);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |