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 ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define setpre(i) setprecision(i)<<fixed
#define foru(i, a, b) for(int i=a;i<=b;++i)
#define ford(i, a, b) for(int i=a;i>=b;--i)
#define mp make_pair
#define moo cout<<"moo "
#define fi first
#define se second
ll lmod = 1e9 + 7;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int, int> ii;
typedef pair<double, double> dd;
ll dp[20][2][2][11][11];
string num;
ll solve(int pos, bool under, bool started, int dig1, int dig2){
ll &ans = dp[pos][under][started][dig1][dig2];
if(pos == num.size()){
if(!started) return 0;
else return 1;
}
if(ans != -1) return ans;
ans = 0;
foru(i, 0, 9){
if(!under and i > num[pos] - '0') break;
if(i == dig1 or i == dig2) continue;
if(i) ans += solve(pos + 1, under or i < num[pos] - '0', 1, dig2, i);
else ans += solve(pos + 1, under or i < num[pos] - '0', started, dig2, i);
}
return ans;
}
ll cnt(int x, int y){
num = to_string(y);
memset(dp, -1, sizeof dp);
ll temp1 = solve(0, 0, 0, 10, 10);
// cout << temp1 << endl;
num = to_string(x - 1);
memset(dp, -1, sizeof dp);
ll temp2 = solve(0, 0, 0, 10, 10);
// cout << temp2 << endl;
return temp1 - temp2;
}
int main(){
// freopen("input.inp", "r", stdin);
// freopen("output.out", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// cout << cnt(1, 10);
ll a, b; cin >> a >> b;
cout << cnt(a, b) << endl;
// fclose(stdout);
}
Compilation message (stderr)
numbers.cpp: In function 'long long int solve(int, bool, bool, int, int)':
numbers.cpp:27:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | if(pos == num.size()){
| ~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |