fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28.  
  29.  
  30. vector<int> a;
  31. vector<int> b;
  32.  
  33. vector<int> consistency(int n){
  34.  
  35. vector<vector<int>> dpa(n, vector<int>(2, 0));
  36. vector<vector<int>> dpb(n, vector<int>(2, 0));
  37.  
  38. if(a[0] & 1){
  39. dpa[0][0] = 1;
  40. dpa[0][1] = 0;
  41. }
  42. else{
  43. dpa[0][0] = 0;
  44. dpa[0][1] = 1;
  45. }
  46.  
  47.  
  48. if(b[0] & 1){
  49. dpb[0][0] = 1;
  50. dpb[0][1] = 0;
  51. }
  52. else{
  53. dpb[0][0] = 0;
  54. dpb[0][1] = 1;
  55. }
  56.  
  57.  
  58. for(int i=1; i<n; i++){
  59. if(a[i] & 1){
  60. dpa[i][0] = dpa[i-1][1] + dpb[i-1][1];
  61. dpa[i][1] = dpa[i-1][0] + dpb[i-1][0];
  62. }
  63. else{
  64. dpa[i][0] = dpa[i-1][0] + dpb[i-1][0];
  65. dpa[i][1] = dpa[i-1][1] + dpb[i-1][1];
  66. }
  67.  
  68. if(b[i] & 1){
  69. dpb[i][0] = dpa[i-1][1] + dpb[i-1][1];
  70. dpb[i][1] = dpa[i-1][0] + dpb[i-1][0];
  71. }
  72. else{
  73. dpb[i][0] = dpa[i-1][0] + dpb[i-1][0];
  74. dpb[i][1] = dpa[i-1][1] + dpb[i-1][1];
  75. }
  76. }
  77.  
  78. return {dpa[n-1][0] + dpb[n-1][0] , dpa[n-1][1] + dpb[n-1][1]};
  79.  
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. int practice(int n){
  97.  
  98.  
  99. return 0;
  100. }
  101.  
  102.  
  103.  
  104.  
  105.  
  106. void solve() {
  107.  
  108. int n;
  109. cin>> n;
  110.  
  111. a.resize(n);
  112. for(int i=0; i<n; i++) cin >> a[i];
  113. b.resize(n);
  114. for(int i=0; i<n; i++) cin >> b[i];
  115.  
  116. auto ans = consistency(n);
  117.  
  118. cout << "Odd ways : " << ans[0] << " , Even ways : " << ans[1] << endl;
  119.  
  120.  
  121. }
  122.  
  123.  
  124.  
  125.  
  126.  
  127. int32_t main() {
  128. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  129.  
  130. int t = 1;
  131. // cin >> t;
  132. while (t--) {
  133. solve();
  134. }
  135.  
  136. return 0;
  137. }
Success #stdin #stdout 0.01s 5324KB
stdin
4
5 4 1 3
2 1 4 6
stdout
Odd ways : 8 , Even ways : 8