// A + B by Jerzy Kraszewski #include <iostream> #include <string> #include <algorithm> using namespace std; long long dp[20]; int liczby[20] = {1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1}; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); string n; cin >> n; // for (int i = 0; i <= 18; ++i) // cout << i << ": " << liczby[i] << "\n"; dp[0] = 1; for (int i = 1; i <= n.size(); ++i){ int l = n[i-1] - 48; // cout << i << " " << l << "\n"; dp[i] = dp[i-1] * liczby[l]; if (i > 1 && l < 9 && n[i-2] - 48 == 1){ l += 10; dp[i] += dp[i-2] * liczby[l]; } } // for (int i = 0; i <= n.size(); ++i) // cout << i << ": " << dp[i] << "\n"; cout << dp[n.size()] << "\n"; }
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 | // A + B by Jerzy Kraszewski #include <iostream> #include <string> #include <algorithm> using namespace std; long long dp[20]; int liczby[20] = {1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1}; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); string n; cin >> n; // for (int i = 0; i <= 18; ++i) // cout << i << ": " << liczby[i] << "\n"; dp[0] = 1; for (int i = 1; i <= n.size(); ++i){ int l = n[i-1] - 48; // cout << i << " " << l << "\n"; dp[i] = dp[i-1] * liczby[l]; if (i > 1 && l < 9 && n[i-2] - 48 == 1){ l += 10; dp[i] += dp[i-2] * liczby[l]; } } // for (int i = 0; i <= n.size(); ++i) // cout << i << ": " << dp[i] << "\n"; cout << dp[n.size()] << "\n"; } |