#include<bits/stdc++.h>usingnamespacestd;#define base 37typedeflonglongll;intconstmaxValue=base*base*base*base;intn,d;intf[maxValue];intdigit(charx,boolisequal){if(!isequal)returnbase-1;returnx<='9'?x-'0':10+x-'a';}intbase37(strings,intmask){intres=digit(s[0],mask&1);for(inti=1;i<4;i++)res=res*base+digit(s[i],(mask>>i)&1);returnres;}intfixcount(intb){intres=4;while(b){if(b%base==base-1)res--;b/=base;}returnres;}voidenter(){cin>>n>>d;memset(f,0,sizeoff);for(inti=1;i<=n;i++){strings;cin>>s;for(intmask=0;mask<16;mask++)f[base37(s,mask)]++;}}voidsolve(){intfix[5]={0,0,0,0,0},g[5];for(intb=0;b<maxValue;b++)fix[fixcount(b)]+=ll(f[b])*(f[b]-1)/2;if(d==1)cout<<fix[3]<<'\n';if(d==2)cout<<fix[2]-3*fix[3]<<'\n';if(d==3)cout<<fix[1]-2*fix[2]+3*fix[3]<<'\n';if(d==4)cout<<fix[0]-fix[1]+fix[2]-fix[3]<<'\n';}intmain(){ios::sync_with_stdio(0);cin.tie(0);enter();solve();}
Tổng cộng 2 trả lời
Một code khác để tham khảo:
Code tham khảo: