#include <bits/stdc++.h> using u32 = uint32_t; using u64 = uint64_t; using i32 = int32_t; using i64 = int64_t; u64 sum = 0; std::unordered_map<u32, u32> lut; std::vector<u32> v; void f(u64 psum = 1, u32 start = 0) { for(u32 i=start; i<v.size(); ++i) { if(v[i] == 1 && i+1 < v.size() && v[i+1] < 9) { f(psum*lut[10+v[i+1]], i+2); } psum*=lut[v[i]]; } sum += psum; } int main() { std::ios_base::sync_with_stdio(0); for(u32 i=0;i<10;++i) { lut[i]=i+1; } u32 t=9; for(u32 i=10;i<19;++i) { lut[i]=t; --t; } std::string s; std::cin >> s; v.resize(s.size()); std::transform(s.begin(), s.end(), v.begin(), [](auto c){ return c - '0'; }); f(); std::cout << sum << '\n'; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <bits/stdc++.h> using u32 = uint32_t; using u64 = uint64_t; using i32 = int32_t; using i64 = int64_t; u64 sum = 0; std::unordered_map<u32, u32> lut; std::vector<u32> v; void f(u64 psum = 1, u32 start = 0) { for(u32 i=start; i<v.size(); ++i) { if(v[i] == 1 && i+1 < v.size() && v[i+1] < 9) { f(psum*lut[10+v[i+1]], i+2); } psum*=lut[v[i]]; } sum += psum; } int main() { std::ios_base::sync_with_stdio(0); for(u32 i=0;i<10;++i) { lut[i]=i+1; } u32 t=9; for(u32 i=10;i<19;++i) { lut[i]=t; --t; } std::string s; std::cin >> s; v.resize(s.size()); std::transform(s.begin(), s.end(), v.begin(), [](auto c){ return c - '0'; }); f(); std::cout << sum << '\n'; return 0; } |