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 <iostream>
#include <cstring>
using namespace std;
string tostring(long long int a) {
if (a == 0) return "0";
string res = "";
while (a != 0) {
res = char(a % 10 + 48) + res;
a /= 10;
}
return res;
}
long long int f[25][2][15][15];
long long int trya(string s, int i, int smaller, int x, int y) {
if (i == s.size()) {
return 1;
}
if (f[i][smaller][x][y] != -1) return f[i][smaller][x][y];
long long int h = 9, res = 0;
if (smaller == 0) h = s[i] - '0';
for (int j = 0; j <= h; j++) {
if (j == x || j == y) continue;
res += trya(s, i + 1, smaller | (j != h), j, x);
}
//cout << i << " " << smaller << " " << x << " " << y << " " << res << endl;
f[i][smaller][x][y] = res;
return res;
}
int main() {
long long int l, r;
cin >> l >> r;
l--;
memset(f, -1, sizeof f);
string s = tostring(r);
long long int h = trya(s, 0, 0, 10, 10), k;
if (l < 0) {
k = 0;
}
else {
memset(f, -1, sizeof f);
string t = tostring(l);
k = trya(t, 0, 0, 10, 10);
}
//cout << h << " " << k << endl;
cout << h - k;
}
Compilation message (stderr)
numbers.cpp: In function 'long long int trya(std::string, int, int, int, int)':
numbers.cpp:15:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | if (i == s.size()) {
| ~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |