Download spoj_cpp_clean/ACODE/ACODE-8.cpp from slayone/uva_spoj_raw: direct link, hf CLI and curl.
- Browser
- Download file 3.88 kB
-
https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/spoj_cpp_clean/ACODE/ACODE-8.cpp
- Command line
-
hf download hf://datasets/slayone/uva_spoj_raw/spoj_cpp_clean/ACODE/ACODE-8.cpp
-
curl -L -o ACODE-8.cpp https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/spoj_cpp_clean/ACODE/ACODE-8.cpp
3.88 kB
| /*************************************************** | |
| * Problem Name : ACODE - Alphacode.cpp | |
| * Problem Link : https://www.spoj.com/problems/ACODE/ | |
| * OJ : Spoj | |
| * Verdict : AC | |
| * Date : 2020-02-19 | |
| * Problem Type : DP | |
| * Author Name : Saikat Sharma | |
| * University : CSE, MBSTU | |
| ***************************************************/ | |
| using namespace std; | |
| using namespace __gnu_pbds; | |
| typedef long long ll; | |
| typedef unsigned long long ull; | |
| template<class T> | |
| using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>; | |
| template<typename T> | |
| using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, | |
| tree_order_statistics_node_update>; | |
| template <typename T> string toString ( T Number ) { | |
| stringstream ss; | |
| ss << Number; | |
| return ss.str(); | |
| } | |
| template<typename T> int toInt (T str) { | |
| stringstream ss; | |
| ss << str; | |
| int num; | |
| ss >> num; | |
| return num; | |
| } | |
| ll lcm (ll a, ll b) { | |
| return a * b / __gcd (a, b); | |
| } | |
| /************************************ Code Start Here ******************************************************/ | |
| const int MAX_N = 5005; | |
| string str; | |
| ll dp[MAX_N][105]; | |
| ll fun (int pos, int x) { | |
| if (pos >= (int) str.size() ) { | |
| if (x <= 26 && x > 0) return 1LL; | |
| else return 0LL; | |
| } | |
| ll &res = dp[pos][x]; | |
| if (res != -1) return res; | |
| ll res1 = 0, res2 = 0; | |
| if (str[pos] != '0') { | |
| if (pos + 1 < (int) str.size() ) { | |
| if (str[pos + 1] != '0') { | |
| res1 = fun (pos + 1, str[pos] - '0'); | |
| int val = (str[pos] - '0') * 10 + (str[pos + 1] - '0'); | |
| if (val <= 26) res2 = fun (pos + 2, val); | |
| } else { | |
| int val = (str[pos] - '0') * 10 + (str[pos + 1] - '0'); | |
| if (val <= 26) res2 = fun (pos + 2, val); | |
| } | |
| } else { | |
| res1 = fun (pos + 1, str[pos] - '0'); | |
| } | |
| } | |
| return res = res1 + res2; | |
| } | |
| int main () { | |
| __FastIO; | |
| //~ cout << setprecision (10); | |
| //~ cout << fixed; | |
| while (cin >> str) { | |
| if (str == "0") break; | |
| SET (dp, -1); | |
| ll res = fun (0, 0); | |
| cout << res << "\n"; | |
| } | |
| return 0; | |
| } | |
| //1013 | |