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
const int MAXN = 19;
int dp[MAXN][2][11][11];
string s;
int d(int i) {
return (s[i] - '0');
}
int calc(int x) {
if (x < 1) return x + 1;
s = to_string(x);
int tam = s.size();
reverse(s.begin(), s.end());
memset(dp, 0, sizeof dp);
for (int i = 0; i <= 9; i++) dp[0][1][i][10] = 1;
for (int i = 0; i <= d(0); i++) dp[0][0][i][10] = 1;
for (int i = 1; i < tam; i++) {
// calc 1
for (int a = 0; a <= 9; a++) {
for (int b = 0; b <= 9; b++) {
for (int c = 0; c <= 10; c++) {
if ((a == b) || (a == c)) continue;
dp[i][1][a][b] += dp[i - 1][1][b][c];
}
}
}
// calc 0
for (int a = 0; a < d(i); a++) {
for (int b = 0; b <= 9; b++) {
for (int c = 0; c <= 10; c++) {
if ((a == b) || (a == c)) continue;
dp[i][0][a][b] += dp[i - 1][1][b][c];
}
}
}
int a = d(i);
for (int b = 0; b <= 9; b++) {
for (int c = 0; c <= 10; c++) {
if ((a == b) || (a == c)) continue;
dp[i][0][a][b] += dp[i - 1][0][b][c];
}
}
}
int ans = 1;
for (int i = 0; i < (tam - 1); i++) {
for (int b = 1; b <= 10; b++) {
for (int c = 0; c <= 10; c++) {
ans += dp[i][1][b][c];
}
}
}
for (int b = 1; b <= 10; b++) {
for (int c = 0; c <= 10; c++) {
ans += dp[tam - 1][0][b][c];
//cout << b << " " << c << " " << dp[tam - 1][0][b][c] << "\n";
}
}
return ans;
}
int32_t main() {
int a, b;
cin >> a >> b;
cout << calc(b) - calc(a - 1) << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |