fork download
  1. /*
  2. ID: shubham147
  3. TASK: gift1
  4. LANG: C++14
  5. */
  6. // #include <ext/pb_ds/assoc_container.hpp> // Common file
  7. // #include <ext/pb_ds/tree_policy.hpp>
  8. // #include <functional> // for less
  9. #include<bits/stdc++.h>
  10. // #pragma GCC optimize("Ofast")
  11. // #pragma GCC target("avx,avx2,fma")
  12. // #pragma GCC optimization("unroll-loops")
  13. // #pragma GCC optimize("unroll-loops")
  14. // #pragma GCC optimize("fast-math")
  15. // #pragma GCC optimize("no-stack-protector")
  16. #define ll long long
  17. #define f(i,a,b) for(ll i=a;i<b;i++)
  18. #define mod 1000000007
  19. #define mp make_pair
  20. #define ff first
  21. #define ss second
  22. #define rf(i,a,b) for(ll i=a;i>=b;i--)
  23. #define sc(a) scanf("%lld",&a)
  24. #define pf printf
  25. #define sz(a) (int)(a.size())
  26. #define psf push_front
  27. #define ppf pop_front
  28. #define ppb pop_back
  29. #define pb push_back
  30. #define pq priority_queue
  31. #define all(s) s.begin(),s.end()
  32. #define sp(a) setprecision(a)
  33. #define rz resize
  34. #define ld long double
  35. #define inf (ll)1e18
  36. #define ub upper_bound
  37. #define lb lower_bound
  38. #define bs binary_search
  39. #define eb emplace_back
  40. const double pi = acos(-1);
  41. ll binpow(ll a, ll b){ll res=1;while(b!=0){if(b&1)res*=a;a*=a;b>>=1;}return res;}
  42.  
  43. // using namespace __gnu_pbds;
  44. using namespace std;
  45.  
  46. int dp[15][15][15][15][15];
  47.  
  48. bool check(int a, int b, int c, int d, int e)
  49. {
  50. int cnt=0,arr[]={a,b,c,d,e};
  51. f(i,0,5)
  52. {
  53. if(arr[i]<0)
  54. return 0;
  55. if(arr[i]==0)
  56. cnt++;
  57. }
  58. if(cnt>1)
  59. return 0;
  60. else
  61. return 1;
  62. }
  63.  
  64. int fn(int a, int b, int c, int d, int e)
  65. {
  66. if(a+b+c+d+e==1)
  67. return 1;
  68. if(check(a,b,c,d,e))
  69. {
  70. int &ans=dp[a][b][c][d][e];
  71. if(ans==-1)
  72. {
  73. ans=0;
  74. vector<int> arr={a,b,c,d,e};
  75. f(i,0,5)
  76. {
  77. vector<int> temp=arr;
  78. f(j,0,5)
  79. {
  80. if(i==j)
  81. arr[j]++;
  82. else
  83. arr[j]--;
  84. }
  85. ans|=fn(arr[0],arr[1],arr[2],arr[3],arr[4]);
  86. arr=temp;
  87. }
  88. }
  89. return ans;
  90. }
  91. else
  92. return 0;
  93. }
  94.  
  95. int main()
  96. {
  97. ios_base::sync_with_stdio(false);
  98. cin.tie(NULL);
  99. // freopen("gift1.in","r",stdin);
  100. // freopen("gift1.out","w",stdout);
  101. #ifndef ONLINE_JUDGE
  102. freopen("input.txt","r",stdin);
  103. freopen("output.txt","w",stdout);
  104. #endif
  105. ll t=1;
  106. // cin>>t;
  107. f(i,1,t+1)
  108. {
  109. memset(dp,-1,sizeof(dp));
  110. int ans=fn(7,7,9,5,7);
  111. // cout<<ans<<"\n";
  112. if(fn(7,7,9,5,7) == 1)
  113. cout<<"YES\n";
  114. else
  115. cout<<"NO\n";
  116. }
  117. }
Success #stdin #stdout 0s 6432KB
stdin
Standard input is empty
stdout
NO