提交时间:2024-02-29 16:01:38
运行 ID: 26994
#include<bits/stdc++.h> #define int long long #define p1(x) ((x).first) #define p2(x) ((x).second) using namespace std; int n,m; int M; int cnt[400][400]; struct node{ int x,y; inline const double ag(){ return atan2(y,x); } friend bool operator ==(const node A,const node B){ return A.x==B.x&&A.y==B.y; } friend bool operator !=(const node A,const node B){ return A.x!=B.x||A.y!=B.y; } friend bool operator <(const node A,const node B){ double SA=atan2(A.y,A.x),SB=atan2(B.y,B.x); return SA<SB; } }; vector<node>P,NOW; inline bool edge(node A,node B){ return abs(A.x-B.x)+abs(A.y-B.y)==1; } inline bool cmp(int x,int y){return x>y;} int f[2][1<<16]; int id[20],ed[20]; int ID[1<<16],ED[1<<16]; int tk=0; inline int lst(int x){ return __builtin_ctz(x); } inline void add(int &x,int y){ x+=y; if(!tk)x%=M; } signed main(){ // freopen("rainbow.in","r",stdin); // freopen("rainbow.out","w",stdout); ios::sync_with_stdio(0); cin>>n>>m>>M; for(int i=0;i<=n+m;i++) for(int j=0;j<=n+m;j++) if(i*i+j*j>=n*n&&i*i+j*j<(n+m)*(n+m)) P.push_back({i,j}); sort(P.begin(),P.end()); for(node &A:P)A.x++,A.y++,cnt[A.x+1][A.y]++,cnt[A.x-1][A.y]++,cnt[A.x][A.y-1]++,cnt[A.x][A.y+1]++; bool fl=0; f[0][0]=1; int S=0; int mnt=0; for(node X:P){ tk=(tk+1)%8; cnt[X.x-1][X.y]--,cnt[X.x+1][X.y]--,cnt[X.x][X.y+1]--,cnt[X.x][X.y-1]--; auto T=NOW; NOW.clear(); fl^=1; int n=T.size(); int m=0; for(int i=0;i<n;i++){ if(cnt[T[i].x][T[i].y]){ id[i]=1<<m++; NOW.push_back(T[i]); } else id[i]=0; ed[i]=edge(X,T[i]); } NOW.push_back(X); memset(f[fl],0,sizeof(int)*((1<<m+1))); for(int S=0;S<(1<<n);S++){ int l=lst(S); int I=ID[S^(1<<l)]|id[l]; int E=ED[S^(1<<l)]+ed[l]; add(f[fl][I],f[!fl][S]); add(f[fl][I|(1<<m)],f[!fl][S]<<E); // cout<<X.x<<" "<<X.y<<" "<<S<<" "<<f[!fl][S]<<endl; } } int res=0; int n=NOW.size(); for(int S=0;S<(1<<n);S++){ f[fl][S]%=M; int t=__builtin_popcount(S&(S>>1)); res=(res+((f[fl][S]*f[fl][S]%M)<<t))%M; } cout<<res<<endl; cout.flush(); return 0; } /* 300 16 998244353 */