Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstring>
- using namespace std;
- long long dp[19][10][2][2];
- long long solve(size_t n, int pre, string s, bool is_zero, bool tight, string viz = "") {
- if (n==s.size()) {
- return 1;
- }
- if (pre!=-1 && dp[n][pre][is_zero][tight]) {
- cout << "dp_viz: " << viz << '\n';
- return dp[n][pre][is_zero][tight];
- }
- int limit = tight ? s[n]-'0' : 9;
- long long ans = 0;
- for (int i=0; i<=limit; i++) {
- if (i==pre && !is_zero) continue;
- cout << "viz: " << viz+to_string(i) << '\n';
- if (i<limit) {
- ans += solve(n+1, i, s, is_zero && i==0, false, viz+to_string(i));
- } else {
- ans += solve(n+1, i, s, is_zero && i==0, tight, viz+to_string(i));
- }
- }
- if (pre==-1) return ans;
- return dp[n][pre][is_zero][tight] = ans;
- }
- int main() {
- ios_base::sync_with_stdio(0), cin.tie(0);
- long long a, b;
- cin >> a >> b;
- a -= 1;
- string sa = to_string(a);
- string sb = to_string(b);
- long long rb = solve(0, -1, sb, true, true);
- memset(dp, 0, sizeof(dp));
- long long ra = solve(0, -1, sa, true, true);
- cout << rb - ra << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement