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;
long long f[20][2][2][20][10][10][2];
string a, b;
int n;
long long calc(int pos, bool ok1, bool ok2, int start, int prev, int prevPrev, bool check)
{
if (pos == n + 1) return !check;
if (f[pos][ok1][ok2][start][prev][prevPrev][check] != - 1) return f[pos][ok1][ok2][start][prev][prevPrev][check];
int low = 0, high = 9;
if (ok1) low = a[pos] - '0';
if (ok2) high = b[pos] - '0';
long long res = 0;
for (int i = low; i <= high; ++i)
{
bool okI = ok1 && i == a[pos] - '0', okII = ok2 && i == b[pos] - '0';
int first = (!start && i) ? pos : start;
bool okIII = check;
okIII |= (start && i == prev);
okIII |= (pos - start + 1 > 2 && i == prevPrev);
res += calc(pos + 1, okI, okII, first, i, prev, okIII);
}
return f[pos][ok1][ok2][start][prev][prevPrev][check] = res;
}
int main()
{
// freopen("test.inp", "r", stdin);
// freopen("test.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> a >> b;
while (a.size() < b.size()) a = "0" + a;
n = a.size();
a = "p" + a, b = "p" + b;
memset(f, - 1, sizeof(f));
cout << calc(1, 1, 1, 0, 0, 0, 0);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |