Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdio>
- using namespace std;
- #define f first
- #define s second
- #define mp make_pair
- #define pb push_back
- #define INF (1<<30)
- #define ll long long
- const int N = 25;
- ll f(ll x, int k)
- {
- if (x == 0) return 0;
- int c[N] = {0}, len = 0;
- ll ans = 0, dp[4][N][11][2] = {0};
- while (x)
- {
- c[++len] = x % 10;
- x /= 10;
- }
- for (int i = 1; i <= len / 2; i++) swap(c[i], c[len - i + 1]);
- for (int l = 1; l <= len; l++)
- for (int cf = 1; cf < 10; cf++)
- {
- int v = 1, p;
- while (v <= l && cf == c[v]) v++;
- if (v == l + 1) p = 1;
- else if (cf > c[v]) p = 2;
- else p = 0;
- dp[p][l][cf][l >= k] = 1;
- }
- for (int l = 1; l <= len; l++)
- for (int p = 0; p < 3; p++)
- for (int cf = 0; cf < 10; cf++)
- for (int g = 0; g < 2; g++)
- for (int nc = 0; nc < 10; nc++)
- if (nc != cf)
- {
- int top = p;
- for (int add = 1; add <= len - l; add++)
- {
- if (top == 1 && nc > c[l + add]) top = 2;
- else if (top == 1 && nc < c[l + add]) top = 0;
- dp[top][l + add][nc][g | (add >= k)] += dp[p][l][cf][g];
- }
- }
- for (int l = 1; l <= len; l++)
- for (int p = 0; p < (l == len ? 2: 3); p++)
- for (int cf = 0; cf < 10; cf++) ans += dp[p][l][cf][1];
- return ans;
- }
- int main()
- {
- //freopen("interesting.in", "r", stdin);
- //freopen("interesting.out", "w", stdout);
- ll a, b;
- int k;
- cin >> a >> b >> k;
- cout << f(b, k) - f(a - 1, k);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement