Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define ii pair<ll,ll>
- #define fi first
- #define se second
- #define endl '\n'
- #define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
- #define all(x) (x).begin(),(x).end()
- #define sz(x) (int) (x).size()
- #define puf push_front
- #define pof pop_front
- #define pub push_back
- #define pob pop_back
- #define lb lower_bound
- #define ub upper_bound
- mt19937 rng(123123);
- #define ld double
- #define C complex<ld>
- const ld TAU=acosl(0)*4;
- const C a=1,b=exp(complex<ld>(0,1.0/3)*TAU),c=exp(complex<ld>(0,2.0/3)*TAU);
- C fwht[3][3]={
- {a,a,a},
- {a,b,c},
- {a,c,b}
- };
- C ifwht[3][3]={
- {a,a,a},
- {a,c,b},
- {a,b,c}
- };
- int n,k;
- C arr[531450];
- const int THREE[]={1,3,9,27,81,243,729,2187,6561,19683,59049,177147};
- C temp[3];
- int main(){
- scanf("%d%d",&n,&k);
- rep(x,0,n){
- getchar_unlocked();
- int val=0;
- rep(y,0,k){
- val+=THREE[y]*(getchar_unlocked()-'1');
- }
- arr[val]={1,0};
- }
- for (auto it:THREE){
- rep(x,0,531441) if (x/(it*3)==(x+2*it)/(3*(it))){
- temp[0]=arr[x]*fwht[0][0]+arr[x+it]*fwht[0][1]+arr[x+2*it]*fwht[0][2];
- temp[1]=arr[x]*fwht[1][0]+arr[x+it]*fwht[1][1]+arr[x+2*it]*fwht[1][2];
- temp[2]=arr[x]*fwht[2][0]+arr[x+it]*fwht[2][1]+arr[x+2*it]*fwht[2][2];
- rep(i,0,3) arr[x+i*it]=temp[i];
- }
- }
- rep(x,0,531441) arr[x]=arr[x]*arr[x]*arr[x];
- for (auto it:THREE){
- rep(x,0,531441) if (x/(it*3)==(x+2*it)/(3*(it))){
- temp[0]=arr[x]*ifwht[0][0]+arr[x+it]*ifwht[0][1]+arr[x+2*it]*ifwht[0][2];
- temp[1]=arr[x]*ifwht[1][0]+arr[x+it]*ifwht[1][1]+arr[x+2*it]*ifwht[1][2];
- temp[2]=arr[x]*ifwht[2][0]+arr[x+it]*ifwht[2][1]+arr[x+2*it]*ifwht[2][2];
- rep(i,0,3) arr[x+i*it]=temp[i]/complex<ld>({3,0});
- }
- }
- //cout<<(arr[0].real())-n<<endl;
- ll ans=floor(((arr[0].real())-n)/6+0.5);
- cout<<ans<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement