Advertisement
Guest User

Untitled

a guest
Oct 16th, 2021
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define ii pair<ll,ll>
  6. #define fi first
  7. #define se second
  8. #define endl '\n'
  9.  
  10. #define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
  11. #define all(x) (x).begin(),(x).end()
  12. #define sz(x) (int) (x).size()
  13.  
  14. #define puf push_front
  15. #define pof pop_front
  16. #define pub push_back
  17. #define pob pop_back
  18. #define lb lower_bound
  19. #define ub upper_bound
  20.  
  21. mt19937 rng(123123);
  22.  
  23. #define ld double
  24. #define C complex<ld>
  25.  
  26. const ld TAU=acosl(0)*4;
  27.  
  28. const C a=1,b=exp(complex<ld>(0,1.0/3)*TAU),c=exp(complex<ld>(0,2.0/3)*TAU);
  29.  
  30. C fwht[3][3]={
  31.     {a,a,a},
  32.     {a,b,c},
  33.     {a,c,b}
  34. };
  35.  
  36. C ifwht[3][3]={
  37.     {a,a,a},
  38.     {a,c,b},
  39.     {a,b,c}
  40. };
  41.  
  42. int n,k;
  43. C arr[531450];
  44.  
  45. const int THREE[]={1,3,9,27,81,243,729,2187,6561,19683,59049,177147};
  46. C temp[3];
  47.  
  48. int main(){
  49.     scanf("%d%d",&n,&k);
  50.    
  51.     rep(x,0,n){
  52.         getchar_unlocked();
  53.        
  54.         int val=0;
  55.         rep(y,0,k){
  56.             val+=THREE[y]*(getchar_unlocked()-'1');
  57.         }
  58.        
  59.         arr[val]={1,0};
  60.     }
  61.    
  62.     for (auto it:THREE){
  63.         rep(x,0,531441) if (x/(it*3)==(x+2*it)/(3*(it))){
  64.            
  65.             temp[0]=arr[x]*fwht[0][0]+arr[x+it]*fwht[0][1]+arr[x+2*it]*fwht[0][2];
  66.             temp[1]=arr[x]*fwht[1][0]+arr[x+it]*fwht[1][1]+arr[x+2*it]*fwht[1][2];
  67.             temp[2]=arr[x]*fwht[2][0]+arr[x+it]*fwht[2][1]+arr[x+2*it]*fwht[2][2];
  68.             rep(i,0,3) arr[x+i*it]=temp[i];
  69.         }
  70.     }
  71.    
  72.     rep(x,0,531441) arr[x]=arr[x]*arr[x]*arr[x];
  73.    
  74.     for (auto it:THREE){
  75.         rep(x,0,531441) if (x/(it*3)==(x+2*it)/(3*(it))){
  76.            
  77.             temp[0]=arr[x]*ifwht[0][0]+arr[x+it]*ifwht[0][1]+arr[x+2*it]*ifwht[0][2];
  78.             temp[1]=arr[x]*ifwht[1][0]+arr[x+it]*ifwht[1][1]+arr[x+2*it]*ifwht[1][2];
  79.             temp[2]=arr[x]*ifwht[2][0]+arr[x+it]*ifwht[2][1]+arr[x+2*it]*ifwht[2][2];
  80.             rep(i,0,3) arr[x+i*it]=temp[i]/complex<ld>({3,0});
  81.         }
  82.     }
  83.    
  84.     //cout<<(arr[0].real())-n<<endl;
  85.     ll ans=floor(((arr[0].real())-n)/6+0.5);
  86.     cout<<ans<<endl;
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement