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 inf = 1e9;
const ll infl = 1e18;
signed main() {
cin.tie(0)->sync_with_stdio(0);
string a, b;
cin >> a >> b;
string oa = a;
vector<vector<vector<vector<vector<ll>>>>> memo;
char null = '0';
null--;
auto dp = [&](auto& dp, string& s, int i, char prev, char cur, bool free, int start)->ll{
if (i == (int)s.size()) return 1;
int n = s.size();
ll& key = memo[free][i][start][prev-null][cur-null];
if (key != -1) return key;
ll res = 0;
for (char c = '0'; c <= '9'; c++) {
if (c == prev && start <= i-2) continue;
if (c == cur && start <= i-1) continue;
if (free || c <= s[i]) {
res += dp(dp, s, i+1, cur, c, free || c < s[i], start == n && c != '0' ? i : start);
}
}
return key = res;
};
auto calc = [&](string s) {
if (s == "0") return 1ll;
memo = vector(2, vector(s.size(), vector(s.size()+1, vector(11, vector(11, -1ll)))));
return dp(dp, s, 0, null, null, false, s.size());
};
ll res = calc(b) - calc(a) + 1;
for (int i = 1; i < (int)a.size(); i++){
if (a[i] == a[i-1]) {res--; break; }
if (i >1 && a[i] == a[i-2]) {res--; break; }
}
cout << res << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |