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 dp[20][10][10][2][2][2];
int cal(int len, int l, int ll, bool bound, bool zero1, bool zero2, string target) {
if (len == target.size()) {
return 1;
}
if (dp[len][l][ll][bound][zero1][zero2] != -1) {
return dp[len][l][ll][bound][zero1][zero2];
}
int ans = 0;
for (int i = 0; i <= 9; i++) {
if ((!zero1 && i == l) || (!zero2 && i == ll)) {
continue;
} else {
if (bound && i > target[len] - '0') {
break;
}
ans += cal(len + 1, i, l, bound && (i == target[len] - '0'), i == 0 && zero1, zero1, target);
}
}
dp[len][l][ll][bound][zero1][zero2] = ans;
return ans;
}
int32_t main() {
int a, b;
cin >> a >> b;
string s = to_string(a - 1);
string t = to_string(b);
memset(dp, -1, sizeof dp);
int ans = cal(0, 0, 0, true, true, true, t);
memset(dp, -1, sizeof dp);
cout << ans - cal(0, 0, 0, true, true, true, s);
}
Compilation message (stderr)
numbers.cpp: In function 'long long int cal(long long int, long long int, long long int, bool, bool, bool, std::string)':
numbers.cpp:9:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | if (len == target.size()) {
| ~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |