56892023-09-08 19:43:02TuruTamasSzivárványszámokcpp17Time limit exceeded 13/45400ms4920 KiB
//
// Created by tamas on 9/8/23.
//

#include "bits/stdc++.h"
using namespace std;

string s;
int r = 0;

struct vmi {
    bool found_max;
    int val;
    int index;
    bool thing;
};

void f(vmi& dolog) {
    bool found_max = dolog.found_max;
    int val = dolog.val;
    int index = dolog.index;
    bool thing = dolog.thing;
    if (index == s.size()) {
        r++;
        return;
    }
    int num = s[index] - '0';
    if (found_max) {
        int m  = thing ? val : min(num, val);
        for (int i = 0; i <= m; i++) {
            vmi v = (vmi){true, i, index + 1, (bool)(thing | (i < num))};
            f(v);
        }
    }
    else {
        int m = thing ? 9 : min(num, 9);
        for (int i = 0; i <= m; i++) {
            vmi v = (vmi){i < val, i, index+1, (bool)(thing | (i < num))};
            f(v);
        }
    }
}

int main() {
    cin >> s;
    vmi v = (vmi){false, 0, 0, false};
    f(v);
    cout << r-1;
}
SubtaskSumTestVerdictTimeMemory
base13/45
1Accepted0/03ms1880 KiB
2Accepted0/023ms2076 KiB
3Time limit exceeded0/0368ms2256 KiB
4Accepted1/13ms2508 KiB
5Accepted1/13ms2744 KiB
6Wrong answer0/13ms2956 KiB
7Accepted1/12ms3048 KiB
8Accepted1/13ms3196 KiB
9Accepted1/13ms3248 KiB
10Accepted1/13ms3452 KiB
11Accepted1/13ms3660 KiB
12Accepted1/13ms3680 KiB
13Accepted2/29ms3816 KiB
14Accepted2/28ms3904 KiB
15Wrong answer0/210ms3908 KiB
16Wrong answer0/212ms4040 KiB
17Accepted1/112ms4120 KiB
18Time limit exceeded0/2400ms4092 KiB
19Time limit exceeded0/2361ms4228 KiB
20Time limit exceeded0/2324ms3604 KiB
21Time limit exceeded0/3381ms4596 KiB
22Time limit exceeded0/2372ms4572 KiB
23Time limit exceeded0/2372ms4016 KiB
24Time limit exceeded0/2340ms4912 KiB
25Time limit exceeded0/2361ms4912 KiB
26Time limit exceeded0/2368ms4888 KiB
27Time limit exceeded0/2381ms4884 KiB
28Time limit exceeded0/2356ms4920 KiB
29Time limit exceeded0/2368ms4800 KiB
30Time limit exceeded0/2361ms4784 KiB