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;
typedef long long ll;
typedef pair<int, int> ii;
ll dp[20][11][11][2][2][2];
string A, B;
ll f(int pos, int a, int b, bool fa, bool fb, bool start) {
if(pos == B.size()) return 1;
ll &ret = dp[pos][a][b][fa][fb][start];
if(~ret) return ret;
ret = 0;
int l = 0, r = 9;
if(!fa) l = A[pos] - '0';
if(!fb) r = B[pos] - '0';
for(int i = l; i <= r; i++) {
if(i == a || i == b) continue;
if(!i && start) {
ret += f(pos + 1, 10, 10, fa | (i > l), fb | (i < r), 1);
} else {
ret += f(pos + 1, b, i, fa | (i > l), fb | (i < r), 0);
}
} return ret;
}
int main(int argc, char const *argv[]) {
ll a, b;
scanf("%lld %lld", &a, &b);
A = to_string(a);
B = to_string(b);
while(A.size() < B.size()) A = "0" + A;
memset(dp, -1, sizeof dp);
printf("%lld\n", f(0, 10, 10, 0, 0, 1));
}
Compilation message (stderr)
numbers.cpp: In function 'll f(int, int, int, bool, bool, bool)':
numbers.cpp:11:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(pos == B.size()) return 1;
~~~~^~~~~~~~~~~
numbers.cpp: In function 'int main(int, const char**)':
numbers.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &a, &b);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |