fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #include <ext/pb_ds/assoc_container.hpp>
  4. #include <ext/pb_ds/tree_policy.hpp>
  5. using namespace __gnu_pbds;
  6. #define M1 1000000007
  7. #define M2 998244353
  8. #define ll long long int
  9. #define pll pair<ll,ll>
  10. #define mll map<ll,ll>
  11. #define F first
  12. #define S second
  13. #define PB push_back
  14. #define mp make_pair
  15. #define lb lower_bound
  16. #define ub upper_bound
  17. #define V(a) vector<a>
  18. #define endl '\n'
  19. #define test(t) while(t--)
  20. #define PI acos(-1.0)
  21. #define rep(i,a,b) for(ll i=a;i<b;i++)
  22. #define repp(i,b,a) for(ll i=b-1;i>=a;i--)
  23. #define clr(ar, val) memset(ar, val, sizeof(ar))
  24. #define setbits(x) __builtin_popcountll(x)
  25. #define zrobits(x) __builtin_ctzll(x)
  26. #define ps(y) fixed << setprecision(y)
  27. #define all(x) begin(x),end(x)
  28. #define allr(x) rbegin(x),rend(x)
  29. const int inf= 0x3f3f3f3f;
  30. const ll INF= 0x3f3f3f3f3f3f3f3f;
  31. const int dx[4]= { 0, -1, 0, 1 };
  32. const int dy[4]= { -1, 0, 1, 0 };
  33.  
  34. unsigned int randInt (){
  35. static unsigned int tx = 123456789 , ty = 362436069 , tz = 521288629 , tw = 88675123 ;
  36. unsigned int tt = ( tx ^ ( tx << 11 ));
  37. tx = ty ; ty = tz ; tz = tw ;
  38. return ( tw = ( tw^ ( tw >> 19 )) ^ ( tt ^ ( tt >> 8 )) );
  39. }
  40.  
  41. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  42. template<typename T>
  43. #define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
  44. //member functions :
  45. //1. order_of_key(k) : number of elements strictly lesser than k
  46. //2. find_by_order(k) : k-th element in the set
  47.  
  48. ll floor_div(ll a, ll b) {
  49. return a / b - (((a ^ b) < 0) and a % b);
  50. }
  51. ll ceil_div(ll a, ll b){
  52. return a / b + (((a ^ b) >= 0) and a % b);
  53. }
  54.  
  55. inline void INP()
  56. {
  57. #ifndef ONLINE_JUDGE
  58. freopen("input.txt","r",stdin);
  59. freopen("output.txt","w",stdout);
  60. #endif
  61. }
  62.  
  63. void solve()
  64. {
  65. string s;
  66. cin >> s;
  67.  
  68. int dp[s.size()+5];
  69. dp[0] = 1;
  70. if(s[0] != '0') dp[1] = 1;
  71. else dp[1] = 0;
  72. for(int i=1;i<s.size();++i){
  73. if(s[i] == '0'){
  74. if (s[i-1] == '1' || s[i-1] == '2'){
  75. dp[i+1] = dp[i-1];
  76. }
  77. else{
  78. cout << 0 << endl;
  79. return;
  80. }
  81. }
  82. else{
  83. dp[i+1] = dp[i];
  84. if((s[i-1]=='1' || (s[i-1]=='2') and (s[i] - '0')<=6)){
  85. dp[i+1] += dp[i-1];
  86. }
  87. }
  88. }
  89. cout << dp[s.size()] << endl;
  90. }
  91.  
  92. int32_t main(){
  93. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  94. int t=1;
  95. cin>>t;
  96. test(t){
  97. solve();
  98. }
  99. return 0;
  100. }
Success #stdin #stdout 0s 4516KB
stdin
Standard input is empty
stdout
1