pranavsindura

SPOJ - ACODE

Feb 4th, 2021
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define all(x)    x.begin(), x.end()
  3. #define allr(x)   x.rbegin(), x.rend()
  4. #define sz(x)     ((int)x.size())
  5. #define ln(x)     ((int)x.length())
  6. #define mp        make_pair
  7. #define pb        push_back
  8. #define ff        first
  9. #define ss        second
  10. #define endl      '\n'
  11. #define dbg(x)    cout << #x << ": " << x << endl;
  12. #define clr(x,v)  memset(x, v, sizeof(x));
  13. #define fix(x)    cout << setprecision(x) << fixed;
  14. #define FASTIO    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  15. using namespace std;
  16.  
  17. using ll = long long int;
  18. using ld = long double;
  19. using pi = pair<int, int>;
  20.  
  21. const double PI = acos(-1.0);
  22. const double eps = 1e-9;
  23. const ll mod = 1e9 + 7;
  24. const int inf = 1e7;
  25. const int MAXN = 5e3 + 5;
  26.  
  27. ll dp[MAXN];
  28. string s;
  29.  
  30. ll solve(int i)
  31. {
  32.     if(i > ln(s)) return 0;
  33.     if(i == ln(s)) return 1;
  34.  
  35.     ll &ret = dp[i];
  36.     if(~ret) return ret;
  37.  
  38.     ret = 0;
  39.  
  40.     if(i + 1 < ln(s) && s[i] == '1' && s[i + 1] >= '0' && s[i + 1] <= '9')
  41.         ret += solve(i + 2);
  42.    
  43.     if(i + 1 < ln(s) && s[i] == '2' && s[i + 1] >= '0' && s[i + 1] <= '6')
  44.         ret += solve(i + 2);
  45.    
  46.     if(s[i] >= '1' && s[i] <= '9')
  47.         ret += solve(i + 1);
  48.    
  49.     return ret;
  50. }
  51.  
  52. void cp()
  53. {
  54.     while(cin >> s && s[0] != '0')
  55.     {
  56.         clr(dp, -1);
  57.         cout << solve(0) << endl;
  58.     }
  59. }
  60.  
  61. int main()
  62. {
  63.     FASTIO;
  64.     int t;
  65.     t = 1;
  66.     // cin >> t;
  67.     while(t--)
  68.     {
  69.         cp();
  70.     }
  71.     return 0;
  72. }
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment