Iamtui1010

coin

Nov 8th, 2021
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. //#include<bits/stdc++.h>
  2. #include<iostream>
  3. #include<fstream>
  4. #include<vector>
  5. #include<map>
  6.  
  7. #define long long long
  8. #define nln '\n'
  9.  
  10. const long N = 100, MOD = 1e9 + 7;
  11.  
  12. using namespace std;
  13.  
  14. // Global variables: f1, f2, n, a, p
  15.  
  16. fstream f1, f2;
  17.  
  18. inline void openf()
  19. {
  20.     f1.open("coin.inp", ios:: in);
  21.     f2.open("coin.out", ios:: out);
  22. }
  23.  
  24. inline void closef()
  25. {
  26.     f1.close();
  27.     f2.close();
  28. }
  29.  
  30. long n, p;
  31. vector<long> a;
  32.  
  33. void data()
  34. {
  35.     f1.tie(0)->sync_with_stdio(0);
  36.     f2.tie(0)->sync_with_stdio(0);
  37.     cin.tie(0)->sync_with_stdio(0);
  38.     cin >> n >> p;
  39.     for (long i = 0; i != n; ++i)
  40.     {
  41.         long x;
  42.         cin >> x;
  43.         a.push_back(x);
  44.     }
  45. }
  46.  
  47.     long odd = 0, eve = 1;
  48.  
  49. void process()
  50. {
  51.     for (long i = 0; i != n; ++i)
  52.     {  
  53.         if (a[i] % 2)  
  54.         {
  55.             long tem = odd;
  56.             odd += eve % MOD;
  57.             eve += tem % MOD;
  58.         }
  59.         else
  60.         {
  61.             odd += odd % MOD;
  62.             eve += eve % MOD;
  63.         }
  64.     }
  65. }
  66.  
  67. void view()
  68. {
  69.     if (p == 1)
  70.         cout << odd % MOD << nln;
  71.     else
  72.         cout << eve % MOD << nln;
  73. }
  74.  
  75. int main()
  76. {
  77.     openf();
  78.     data();
  79.     process();
  80.     view();
  81.     closef();
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment