56912023-09-08 20:02:04TuruTamasSzivárványszámokcpp17Wrong answer 13/454ms5104 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;
    bool operator<(const vmi& a) const {
        if (found_max != a.found_max)
            return found_max < a.found_max;
        if (val != a.val)
            return val < a.val;
        if (index != a.index)
            return index < a.index;
        if (thing != a.thing)
            return thing < a.thing;
        return false;
    }
};

map<vmi, int> cache;

void f(vmi& dolog) {
    if (cache.count(dolog)) {
        r += cache[dolog];
        return;
    }
    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';
    int old_r = r;
    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);
        }
    }
    if (!cache.count(dolog)) {
        cache.emplace(dolog, r - old_r);
    }
}

int main() {
    cin >> s;
    vmi v = (vmi){false, 0, 0, false};
    f(v);
    cout << r-1;
}
SubtaskSumTestVerdictTimeMemory
base13/45
1Accepted0/03ms2028 KiB
2Accepted0/03ms2148 KiB
3Wrong answer0/03ms2544 KiB
4Accepted1/13ms2472 KiB
5Accepted1/13ms2628 KiB
6Wrong answer0/13ms2760 KiB
7Accepted1/12ms2836 KiB
8Accepted1/13ms2972 KiB
9Accepted1/13ms3184 KiB
10Accepted1/13ms3268 KiB
11Accepted1/13ms3268 KiB
12Accepted1/13ms3396 KiB
13Accepted2/23ms3484 KiB
14Accepted2/23ms3620 KiB
15Wrong answer0/23ms3720 KiB
16Wrong answer0/23ms3720 KiB
17Accepted1/13ms3848 KiB
18Wrong answer0/23ms4212 KiB
19Wrong answer0/23ms4548 KiB
20Wrong answer0/24ms4416 KiB
21Wrong answer0/34ms4428 KiB
22Wrong answer0/23ms4476 KiB
23Wrong answer0/23ms4552 KiB
24Wrong answer0/23ms4684 KiB
25Wrong answer0/24ms4836 KiB
26Wrong answer0/24ms4840 KiB
27Wrong answer0/24ms4868 KiB
28Wrong answer0/24ms5104 KiB
29Wrong answer0/24ms5060 KiB
30Wrong answer0/24ms5064 KiB