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;
using ll = long long;
const int mxN = 19;
const int mxD = 11;
ll dp[mxN][mxD][mxD][2];
ll go(string& S, int i, int j, int k, int f) {
if ("-1" == S) {
return 0;
}
if (size(S) == i) {
return 1;
}
if (0 <= dp[i][j][k][f]) {
return dp[i][j][k][f];
}
ll& val = dp[i][j][k][f];
val = 0;
if (0 == k) {
val += go(S, i + 1, j, k, 0);
}
int st = 1 + (1 > k);
int d = S[i] - '0' + 1;
for (int l = st; l < mxD; l ++) {
if (l ^ j && l ^ k) {
if (l < d || 0 == f) {
val += go(S, i + 1, k, l, 0);
} else if (l == d) {
val += go(S, i + 1, k, l, 1);
}
}
}
return val;
}
main() {
ll a;
string B;
cin >> a >> B;
string A = to_string(a - 1);
memset(dp, 0xc0, sizeof(dp));
ll ans = go(B, 0, 0, 0, 1);
memset(dp, 0xc0, sizeof(dp));
ans -= go(A, 0, 0, 0, 1);
cout << ans << endl;
}
Compilation message (stderr)
numbers.cpp: In function 'll go(std::string&, int, int, int, int)':
numbers.cpp:15:17: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
15 | if (size(S) == i) {
| ~~~~~~~~^~~~
numbers.cpp: At global scope:
numbers.cpp:40:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
40 | main() {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |