Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // WA all region C second tour 15/16
- # include <iostream>
- # include <map>
- using namespace std;
- int32_t count_n(int32_t x) {
- int32_t cur_count = 0;
- while (x != 0) {
- x /= 10;
- cur_count++;
- }
- return cur_count;
- }
- void ans(int32_t &n, int32_t k, int32_t cur, int32_t &barrier, int32_t &count, map<int32_t, bool> &counted) {
- if (cur <= barrier && cur != 0 && !counted[cur]) {
- count++;
- counted[cur] = true;
- }
- if (k != n) {
- for (size_t i = cur % 10; i < 10; i++) {
- if (!(cur == 0 && i == 0)) {
- ans(n, k + 1, cur * 10 + i, barrier, count, counted);
- }
- }
- }
- }
- int main() {
- int32_t left, right;
- int32_t count, n;
- map<int32_t, bool> counted;
- cin >> left;
- cin >> right;
- n = count_n(right);
- ans(n, 0, 0, right, count, counted);
- cout << count;
- return 0;
- }
Add Comment
Please, Sign In to add comment