提交时间:2024-02-29 19:03:10
运行 ID: 27009
#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); if(SA==SB)return A.y<B.y; 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; for(node X:P){ tk=(tk+1)%8; cnt[X.x-1][X.y]--,cnt[X.x+1][X.y]--; if(X.x!=1) 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; if(edge(X,T[i])&&(X.x!=1||T[i].x!=1))ed[i]=1; else ed[i]=0; } NOW.push_back(X); memset(f[fl],0,sizeof(int)*((1<<m+1))); // cout<<X.x<<"x"<<X.y<<endl; for(int S=0;S<(1<<n);S++){ if(!tk) f[!fl][S]%=M; if(!S){ ID[S]=ED[S]=0; add(f[fl][S],f[!fl][S]); add(f[fl][S|(1<<m)],f[!fl][S]); } else{ int l=lst(S); ID[S]=ID[S^(1<<l)]|id[l]; ED[S]=ED[S^(1<<l)]+ed[l]; assert(ED[S]<=4); add(f[fl][ID[S]],f[!fl][S]); add(f[fl][ID[S]|(1<<m)],f[!fl][S]<<ED[S]); } // cout<<S<<" "<<f[!fl][S]<<endl; } // cout<<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)); // cout<<S<<" "<<f[fl][S]<<endl; res=(res+((f[fl][S]*f[fl][S]%M)<<t))%M; } cout<<res<<endl; cout.flush(); return 0; } /* 2 2 998244353 */