// Daniel Grzegorzewski // while (clock()<=69*CLOCKS_PER_SEC) #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") #define MP make_pair #define PB push_back #define ST first #define ND second #define int long long using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego) //X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<PII> VII; typedef long long LL; void init_ios() { ios_base::sync_with_stdio(0); cin.tie(0); } int n, cnt[100]; string s; int calc(int l, int r) { if (l > r) return 1; if (l == r) return cnt[s[l]-'0']; int dod = cnt[10*(s[r-1]-'0')+s[r]-'0']*calc(l, r-2); if (s[r-1] != '1') dod = 0; return cnt[s[r]-'0']*calc(l, r-1)+dod; } signed main() { init_ios(); for (int i = 0; i < 19; ++i) for (int j = 0; j <= min(9LL, i); ++j) if (i-j < 10) ++cnt[i]; cin >> s; n = s.size(); cout<<calc(0, n-1)<<"\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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | // Daniel Grzegorzewski // while (clock()<=69*CLOCKS_PER_SEC) #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") #define MP make_pair #define PB push_back #define ST first #define ND second #define int long long using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego) //X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<PII> VII; typedef long long LL; void init_ios() { ios_base::sync_with_stdio(0); cin.tie(0); } int n, cnt[100]; string s; int calc(int l, int r) { if (l > r) return 1; if (l == r) return cnt[s[l]-'0']; int dod = cnt[10*(s[r-1]-'0')+s[r]-'0']*calc(l, r-2); if (s[r-1] != '1') dod = 0; return cnt[s[r]-'0']*calc(l, r-1)+dod; } signed main() { init_ios(); for (int i = 0; i < 19; ++i) for (int j = 0; j <= min(9LL, i); ++j) if (i-j < 10) ++cnt[i]; cin >> s; n = s.size(); cout<<calc(0, n-1)<<"\n"; } |