Advertisement
Dang_Quan_10_Tin

TRASHCODE

Oct 13th, 2020
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #define task "xorseq"
  5.  
  6. using namespace std;
  7. using ll = long long;
  8. using ld = long double;
  9.  
  10. const int N = 1e2 + 5;
  11. int n;
  12. ll k;
  13. ll a[N];
  14. const ll mod = 998244353;
  15.  
  16. struct Matrix
  17. {
  18.     ll a[N][N];
  19.     Matrix()
  20.     {
  21.         memset(a, 0, sizeof a);
  22.     }
  23.     Matrix operator*(const Matrix &x)
  24.     {
  25.         Matrix ans;
  26.         for (int i = 1; i <= n; ++i)
  27.             for (int j = 1; j <= n; ++j)
  28.                 for (int k = 1; k <= n; ++k)
  29.                     (ans.a[i][j] += a[i][k] * x.a[k][j]) %= mod;
  30.         return ans;
  31.     }
  32. } base, v;
  33.  
  34. Matrix Pow(Matrix &a, ll k)
  35. {
  36.     Matrix ans;
  37.     for (int i = 1; i <= n; ++i)
  38.         ans.a[i][i] = 1;
  39.     for (; k > 0; k >>= 1)
  40.     {
  41.         if (k & 1)
  42.             ans = ans * a;
  43.         a = a * a;
  44.     }
  45.     return ans;
  46. }
  47.  
  48. void Read()
  49. {
  50.     cin >> n >> n >> k;
  51.     for (int i = 1; i <= n; ++i)
  52.     {
  53.         cin >> a[i];
  54.         for (int j = 1; j <= n; ++j)
  55.             if (__builtin_popcountll(a[i] ^ a[j]) % 3 == 0)
  56.                 v.a[i][j] = v.a[j][i] = 1;
  57.     }
  58.     if (k == 1)
  59.     {
  60.         cout << n;
  61.         exit(0);
  62.     }
  63. }
  64.  
  65. void Solve()
  66. {
  67.     v = Pow(v, k - 1);
  68.     for (int i = 1; i <= n; ++i)
  69.         base.a[i][1] = 1;
  70.     v = v * base;
  71.     ll ans = 0;
  72.     for (int i = 1; i <= n; ++i)
  73.         (ans += v.a[i][1]) %= mod;
  74.     cout << ans;
  75. }
  76.  
  77. int32_t main()
  78. {
  79.     ios_base::sync_with_stdio(0);
  80.     cin.tie(0);
  81.     cout.tie(0);
  82.     if (fopen(task ".INP", "r"))
  83.     {
  84.         freopen(task ".INP", "r", stdin);
  85.         freopen(task ".OUT", "w", stdout);
  86.     }
  87.     Read();
  88.     Solve();
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement