kdzhr

Untitled

Jan 9th, 2020
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. // WA all region C second tour 15/16
  2.  
  3. # include <iostream>
  4. # include <map>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int32_t count_n(int32_t x) {
  10.     int32_t cur_count = 0;
  11.     while (x != 0) {
  12.         x /= 10;
  13.         cur_count++;
  14.     }
  15.     return cur_count;
  16. }
  17.  
  18. void ans(int32_t &n, int32_t k, int32_t cur, int32_t &barrier, int32_t &count, map<int32_t, bool> &counted) {
  19.     if (cur <= barrier && cur != 0 && !counted[cur]) {
  20.         count++;
  21.         counted[cur] = true;
  22.     }
  23.     if (k != n) {
  24.         for (size_t i = cur % 10; i < 10; i++) {
  25.             if (!(cur == 0 && i == 0)) {
  26.                 ans(n, k + 1, cur * 10 + i, barrier, count, counted);
  27.             }
  28.         }
  29.     }
  30. }
  31.  
  32. int main() {
  33.     int32_t left, right;
  34.     int32_t count, n;
  35.     map<int32_t, bool> counted;
  36.     cin >> left;
  37.     cin >> right;
  38.     n = count_n(right);
  39.     ans(n, 0, 0, right, count, counted);
  40.     cout << count;
  41.     return 0;
  42. }
Add Comment
Please, Sign In to add comment