Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <cmath>
- #include <iomanip>
- #include <fstream>
- #include <string>
- #include <set>
- #include <deque>
- #include <queue>
- #include <map>
- #include <bitset>
- #include <random>
- #include <cassert>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef long double ld;
- #define sqrt sqrtl
- #define endl "\n"
- #define all(a) a.begin(), a.end()
- #define pb push_back
- #define F first
- #define S second
- const ll inf = 1e18;
- long double eps = 1e-18;
- ll mod = 1e9 + 7;
- const ll MAXN = 1 << 20;
- const ll maxs = 1 << 20;
- template <typename T>
- istream& operator >> (istream& in, vector <T>& a) {
- for (T& i : a) {
- in >> i;
- }
- return in;
- }
- template <typename T>
- ostream& operator << (ostream& out, vector <T>& a) {
- for (T& i : a) {
- out << i << ' ';
- }
- return out;
- }
- const int N = 1e5 + 10;
- int dp[N][20][11][2];
- int dp_cnt(string& s) {
- if (s == "0")
- return 1;
- for (int i = 0; i < N; i++) {
- for (int d = 0; d < 20; d++) {
- for (int last = 0; last < 11; last++) {
- for (int f = 0; f < 2; f++) {
- dp[i][d][last][f] = 0;
- }
- }
- }
- }
- dp[0][0][10][1] = 1;
- for (int i = 0; i < s.size(); i++) {
- for (int d = 0; d < 20; d++) {
- int dif = d - 10;
- for (int last = 0; last < 11; last++) {
- for (int k = 0; k < 2; k++) {
- if (d == 0) {
- for (int newd = 0; newd <= (int)(k == 1 ? s[i] - '0' : 9); newd++) {
- if (last != 10) {
- dp[i + 1][newd - last + 10][newd][(k == 1 && newd == s[i] - '0')] += dp[i][d][last][k];
- }
- else {
- if (newd&1)
- dp[i + 1][0][newd][(k == 1 && newd == s[i] - '0')] += dp[i][d][last][k];
- else {
- dp[i + 1][0][10][(k == 1 && newd == s[i] - '0')] += dp[i][d][last][k];
- }
- }
- }
- }
- else {
- if (k == 1 && (last + dif + 10) % 10 > s[i] - '0')
- continue;
- int buffer = (k == 1 && (last + dif + 10) % 10 == s[i] - '0');
- dp[i + 1][d][(last + dif + 10) % 10][buffer] += dp[i][d][last][k];
- }
- }
- }
- }
- }
- int ans = 0;
- for (int d = 0; d < 20; d++)
- for (int last = 0; last < 11; last++)
- for (int f = 0; f < 2; f++)
- ans += dp[s.size()][d][last][f];
- return ans;
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- string l, r;
- cin >> l >> r;
- int i = l.size() - 1;
- while (l[i] == '0') {
- l[i] = '9';
- i--;
- }
- l[i]--;
- cout << dp_cnt(r) - dp_cnt(l);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement