56902023-09-08 19:58:57TuruTamasSzivárványszámokcpp17Wrong answer 2/456ms5120 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)) {
        cout << cache[dolog] << "\n";
        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
base2/45
1Wrong answer0/03ms1876 KiB
2Wrong answer0/03ms2080 KiB
3Wrong answer0/04ms2496 KiB
4Accepted1/13ms2780 KiB
5Accepted1/12ms2592 KiB
6Wrong answer0/13ms2876 KiB
7Wrong answer0/13ms2908 KiB
8Wrong answer0/13ms3124 KiB
9Wrong answer0/13ms3372 KiB
10Wrong answer0/13ms3536 KiB
11Wrong answer0/13ms3776 KiB
12Wrong answer0/13ms3996 KiB
13Wrong answer0/23ms4048 KiB
14Wrong answer0/23ms4048 KiB
15Wrong answer0/23ms4064 KiB
16Wrong answer0/23ms4152 KiB
17Wrong answer0/13ms4360 KiB
18Wrong answer0/24ms4748 KiB
19Wrong answer0/24ms4716 KiB
20Wrong answer0/24ms4744 KiB
21Wrong answer0/36ms4900 KiB
22Wrong answer0/23ms4904 KiB
23Wrong answer0/23ms4880 KiB
24Wrong answer0/23ms4884 KiB
25Wrong answer0/24ms5084 KiB
26Wrong answer0/24ms5120 KiB
27Wrong answer0/24ms5052 KiB
28Wrong answer0/26ms5072 KiB
29Wrong answer0/26ms5064 KiB
30Wrong answer0/26ms5068 KiB