#include <bits/stdc++.h> using u32 = uint32_t; using u64 = uint64_t; using i32 = int32_t; using i64 = int64_t; const std::vector<std::pair<u64, u64>> vec_of_known_pairs = {std::make_pair(0, 1), std::make_pair(1, 2), std::make_pair(2, 3), std::make_pair(3, 4), std::make_pair(4, 5), std::make_pair(5, 6), std::make_pair(6, 7), std::make_pair(7, 8), std::make_pair(8, 9), std::make_pair(9, 10), std::make_pair(10, 9), std::make_pair(11, 8), std::make_pair(12, 7), std::make_pair(13, 6), std::make_pair(14, 5), std::make_pair(15, 4), std::make_pair(16, 3), std::make_pair(17, 2), std::make_pair(18, 1)}; u64 FINAL_RESULT = 0; void solve(std::vector<u64> &digits, u64 tmp_sum = 1, u64 initial_digit_id = 0) { for (u64 i = initial_digit_id; i < digits.size(); i++) { if (digits[i] == 1 and digits[i + 1] < 9 and i + 1 < digits.size()) { auto it = std::find_if(vec_of_known_pairs.begin(), vec_of_known_pairs.end(), [&](auto x) { return x.first == digits[i + 1] + 10; }); solve(digits, tmp_sum * it->second, i + 2); } auto it = std::find_if(vec_of_known_pairs.begin(), vec_of_known_pairs.end(), [&](auto x) { return x.first == digits[i]; }); tmp_sum *= it->second; } FINAL_RESULT += tmp_sum; } int main() { std::ios_base::sync_with_stdio(0); std::string str; std::cin >> str; std::vector<u64> digits(str.size()); std::transform(str.begin(), str.end(), digits.begin(), [](auto c) { return c - '0'; }); solve(digits); std::cout << FINAL_RESULT << std::endl; 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 | #include <bits/stdc++.h> using u32 = uint32_t; using u64 = uint64_t; using i32 = int32_t; using i64 = int64_t; const std::vector<std::pair<u64, u64>> vec_of_known_pairs = {std::make_pair(0, 1), std::make_pair(1, 2), std::make_pair(2, 3), std::make_pair(3, 4), std::make_pair(4, 5), std::make_pair(5, 6), std::make_pair(6, 7), std::make_pair(7, 8), std::make_pair(8, 9), std::make_pair(9, 10), std::make_pair(10, 9), std::make_pair(11, 8), std::make_pair(12, 7), std::make_pair(13, 6), std::make_pair(14, 5), std::make_pair(15, 4), std::make_pair(16, 3), std::make_pair(17, 2), std::make_pair(18, 1)}; u64 FINAL_RESULT = 0; void solve(std::vector<u64> &digits, u64 tmp_sum = 1, u64 initial_digit_id = 0) { for (u64 i = initial_digit_id; i < digits.size(); i++) { if (digits[i] == 1 and digits[i + 1] < 9 and i + 1 < digits.size()) { auto it = std::find_if(vec_of_known_pairs.begin(), vec_of_known_pairs.end(), [&](auto x) { return x.first == digits[i + 1] + 10; }); solve(digits, tmp_sum * it->second, i + 2); } auto it = std::find_if(vec_of_known_pairs.begin(), vec_of_known_pairs.end(), [&](auto x) { return x.first == digits[i]; }); tmp_sum *= it->second; } FINAL_RESULT += tmp_sum; } int main() { std::ios_base::sync_with_stdio(0); std::string str; std::cin >> str; std::vector<u64> digits(str.size()); std::transform(str.begin(), str.end(), digits.begin(), [](auto c) { return c - '0'; }); solve(digits); std::cout << FINAL_RESULT << std::endl; return 0; } |