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;
auto dp = [&](auto& dp, string& s, int i, char prev, char cur, bool free, bool zeros)->ll{
if (i == (int)s.size()) return 1;
ll& key = memo[free][zeros][i][prev][cur];
if (key != -1) return key;
ll res = 0;
for (char c = '0'; c <= '9'; c++) {
if (!zeros && (c == prev || c == cur)) continue;
if (free || c <= s[i]) {
res += dp(dp, s, i+1, cur, c, free || c < s[i], zeros && c > '0');
}
}
return key = res;
};
auto calc = [&](string s) {
if (s == "0") return 1ll;
memo = vector(2, vector(2, vector(s.size(), vector(128, vector(128, -1ll)))));
return dp(dp, s, 0, '-', '-', false, true);
};
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... |