fork download
  1. // ~~ icebear love attttttt ~~
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7. typedef pair<int, ii> iii;
  8.  
  9. template<class T>
  10. bool minimize(T &a, const T &b) {
  11. if (a > b) return a = b, true;
  12. return false;
  13. }
  14.  
  15. template<class T>
  16. bool maximize(T &a, const T &b) {
  17. if (a < b) return a = b, true;
  18. return false;
  19. }
  20.  
  21. #define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
  22. #define FORR(i,a,b) for(int i=(a); i>=(b); --i)
  23. #define REP(i, n) for(int i=0; i<(n); ++i)
  24. #define RED(i, n) for(int i=(n)-1; i>=0; --i)
  25. #define MASK(i) (1LL << (i))
  26. #define mp make_pair
  27. #define pb push_back
  28. #define fi first
  29. #define se second
  30. #define all(x) x.begin(), x.end()
  31. #define task "icebearat"
  32.  
  33. const int MOD = 1e9 + 7;
  34. const int inf = 1e9 + 27092008;
  35. const ll INF = 1e18 + 27092008;
  36. const int N = 100 + 5;
  37. int dp[N][10][2][2];
  38. string L, R;
  39. vector<int> digit;
  40.  
  41. int DP(int pos, int last, bool start, bool smaller) {
  42. if (pos < 0) return start;
  43. int &ret = dp[pos][last][start][smaller];
  44. if (~ret) return ret;
  45. ret = 0;
  46.  
  47. int limit = (smaller ? 9 : digit[pos]);
  48. FOR(i, 0, limit) {
  49. bool newSt = (start | (i > 0));
  50. if (!newSt || i != last)
  51. ret = (ret + DP(pos - 1, i, newSt, smaller | (i < limit))) % MOD;
  52. }
  53.  
  54. return ret;
  55. }
  56.  
  57. int f(string &x) {
  58. if (x == "0") return 0;
  59. digit.clear();
  60. for(char c : x) digit.pb(c - '0');
  61. reverse(all(digit));
  62. memset(dp, -1, sizeof dp);
  63. return DP((int)digit.size() - 1, 0, 0, 0);
  64. }
  65.  
  66. int check(string &x) {
  67. FOR(i, 1, (int)x.size() - 1) if (x[i] == x[i - 1]) return -1;
  68. return 1;
  69. }
  70.  
  71. void init(void) {
  72. cin >> L >> R;
  73. }
  74.  
  75. void process(void) {
  76. cout << (f(R) - f(L) + check(L) + MOD) % MOD;
  77. }
  78.  
  79. int main() {
  80. ios_base::sync_with_stdio(0);
  81. cin.tie(0); cout.tie(0);
  82. if (fopen(task".inp", "r")) {
  83. freopen(task".inp", "r", stdin);
  84. freopen(task".out", "w", stdout);
  85. }
  86. int tc = 1;
  87. // cin >> tc;
  88. while(tc--) {
  89. init();
  90. process();
  91. }
  92. return 0;
  93. }
  94.  
  95.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
1