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;
string num;
int dp[19][11][11][2];
int mod = 1e9 + 7;
int rec(int pos, int p1, int p2, int f) {
if(pos == num.size()) return 1;
if(dp[pos][p1][p2][f] != -1) return dp[pos][p1][p2][f];
int LIM = 9;
if(!f) LIM = num[pos] - '0';
int res = 0;
for (int i = 0; i<=LIM; i++) {
if(p1 == i || p2 == i) continue;
res += rec(pos+1, i, p1, (f || i < LIM));
if(res >= mod) res -= mod;
}
return dp[pos][p1][p2][f] = res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long A, B;
cin >> A >> B;
num = to_string(B);
if(A == 0) {
memset(dp, -1 ,sizeof(dp));
cout << rec(0, 10, 10, 0) << '\n';
}
else {
A--;
memset(dp, -1 ,sizeof(dp));
B = rec(0, 10, 10, 0);
memset(dp, -1, sizeof(dp)); num = to_string(A);
cout << (B - rec(0, 10, 10, 0) + mod + mod) % mod << '\n';
}
return 0;
}
Compilation message (stderr)
numbers.cpp: In function 'int rec(int, int, int, int)':
numbers.cpp:13:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | if(pos == num.size()) return 1;
| ~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |