Advertisement
Guest User

Untitled

a guest
Oct 16th, 2021
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 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,531441};
  46. C temp[3];
  47.  
  48. const C three={3,0};
  49.  
  50. int main(){
  51.     scanf("%d%d",&n,&k);
  52.    
  53.     rep(x,0,n){
  54.         getchar_unlocked();
  55.        
  56.         int val=0;
  57.         rep(y,0,k){
  58.             val+=THREE[y]*(getchar_unlocked()-'1');
  59.         }
  60.        
  61.         arr[val]={1,0};
  62.     }
  63.    
  64.     for (int step = 1; step < THREE[k]; step *= 3) {
  65.         for (int i = 0; i < THREE[k]; i += 3 * step) rep(j,i,i+step) {
  66.             temp[0]=arr[j]*fwht[0][0]+arr[j+step]*fwht[0][1]+arr[j+2*step]*fwht[0][2];
  67.             temp[1]=arr[j]*fwht[1][0]+arr[j+step]*fwht[1][1]+arr[j+2*step]*fwht[1][2];
  68.             temp[2]=arr[j]*fwht[2][0]+arr[j+step]*fwht[2][1]+arr[j+2*step]*fwht[2][2];
  69.             rep(i,0,3) arr[j+i*step]=temp[i];
  70.         }
  71.     }
  72.    
  73.     rep(x,0,THREE[k]) arr[x]=arr[x]*arr[x]*arr[x];
  74.    
  75.     for (int step = 1; step < THREE[k]; step *= 3) {
  76.         for (int i = 0; i < THREE[k]; i += 3 * step) rep(j,i,i+step) {
  77.             temp[0]=arr[j]*ifwht[0][0]+arr[j+step]*ifwht[0][1]+arr[j+2*step]*ifwht[0][2];
  78.             temp[1]=arr[j]*ifwht[1][0]+arr[j+step]*ifwht[1][1]+arr[j+2*step]*ifwht[1][2];
  79.             temp[2]=arr[j]*ifwht[2][0]+arr[j+step]*ifwht[2][1]+arr[j+2*step]*ifwht[2][2];
  80.             rep(i,0,3) arr[j+i*step]=temp[i]/three;
  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