int n,a[20],x[20],y[20],b1[50],b2[50],ans; intrun(int i) { if (i==n+1) { ans++; if (ans>=4) return0; F(j,1,n) CO a[j] P; CL; return0; }
for (int j=1;j<=n;j++) if (!y[j]&&!b1[i+j]&&!b2[i-j+n]) { b1[i+j]=b2[i-j+n]=y[j]=1; a[i]=j; run(i+1); b1[i+j]=b2[i-j+n]=y[j]=0; } return0; } intmain() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); CI n; run(1); CO ans L; return0; }
int n,m,ans; int a[200][200],b[200][200]; string s;
intrun(int x,int y) { int x1=max(1,x-1); int y1=max(1,y-1); int x2=min(n,x+1); int y2=min(m,y+1); F(i,x1,x2) F(j,y1,y2) { if (i==x&&j==y) continue; if (a[i][j]&&(!b[i][j])) { b[i][j]=1; run(i,j); } } return0; }
intmain() { // ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); CI n>>m; F(i,1,n) { CI s; F(j,1,m) if (s[j-1]=='W') a[i][j]=1; } F(i,1,n) { F(j,1,m) if (a[i][j]&&(!b[i][j])) { run(i,j); ans++; } } CO ans L; return0; }
intrun(int x,int y) { if (x<0||x>n+1||y<0||y>m+1) return0; int zx[4]={-1,0,1,0}; int zy[4]={0,-1,0,1}; F(i,0,3) { if (x+zx[i]>=0&&y+zy[i]>=0&&x+zx[i]<=n+1&&y+zy[i]<=m+1) if (!a[x+zx[i]][y+zy[i]]&&!b[x+zx[i]][y+zy[i]]) { b[x+zx[i]][y+zy[i]]=1; run(x+zx[i],y+zy[i]); } } return0; }
intmain() { // ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); CI n>>m; F(i,1,n) F(j,1,m) { CI c; if (c=='*') a[i][j]=1; } run(0,0);
F(i,1,n) F(j,1,m) if (!b[i][j]&&!a[i][j]) ans++; CO ans L; return0; }
int x,y,t; structPoint { int x,depth; Point(int x,int depth):x(x),depth(depth){}; };
intmain() { // ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); CI t; while (t--) { CI x>>y; int v[MAX+10]={0}; queue<Point> q; v[x]=1; q.push(Point(x,0)); while (!q.empty()) { Point p=q.front(); if (p.x==y) { CO p.depth L; break; }
if (p.x-1>=0&&!v[p.x-1]) { q.push(Point(p.x-1,p.depth+1)); v[p.x-1]=1; } if (p.x+1<=MAX&&!v[p.x+1]) { q.push(Point(p.x+1,p.depth+1)); v[p.x+1]=1; } if (p.x*2<=MAX&&!v[p.x*2]) { q.push(Point(p.x*2,p.depth+1)); v[p.x*2]=1; } q.pop(); } } return0; }
int v[MAX+10][MAX+10]={-1,-1}; int n,m,x,y; int f[8][2]={{-2,-1},{-1,-2},{-2,1},{-1,2},{1,-2},{2,-1},{1,2},{2,1}}; structPoint { int x,y,depth; Point(int x,int y,int depth):x(x),y(y),depth(depth){}; }; queue<Point> q; intmain() { // ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); CI n>>m>>x>>y; q.push(Point(x,y,0));
F(i,1,n) { F(j,1,m) v[i][j]=-1; } v[x][y]=0;
while (!q.empty()) { Point p=q.front();
F(i,0,7) { if (p.x+f[i][0]>=1&&p.x+f[i][0]<=MAX&&p.y+f[i][1]>=1&&p.y+f[i][1]<=MAX&&v[p.x+f[i][0]][p.y+f[i][1]]==-1) { q.push(Point(p.x+f[i][0],p.y+f[i][1],p.depth+1)); v[p.x+f[i][0]][p.y+f[i][1]]=p.depth+1; } } q.pop(); } F(i,1,n) { F(j,1,m) CO v[i][j]<<"\t"; CL } return0; }
int t,n; string s1,s2; intmain() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); CI t; while (t--) { CI n; CI s1>>s2; int x1=0,x2=0; F(i,0,n-1) if (s1[i]!=s2[i]) { if (s1[i]=='1') x1++; else x2++; } if (x1>x2) CO x1 L; else CO x2 L; } return0; }
int t; LL mes,power,use,off; LL a[200005]; intmain() { // ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); CI t; while (t--) { CI mes>>power>>use>>off; F(i,1,mes) CI a[i]; int t=0,f=1; F(i,1,mes) { if ((a[i]-a[i-1])*use<=off) power-=(a[i]-a[i-1])*use; else power-=off; if (power<=0) { f=0; break; } } if (f) CO "YES" L; else CO "NO" L; } return0; }
int t,n,m,xa,ya,xb,yb; intmain() { // ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); CI t; while (t--) { CI n>>m>>xa>>ya>>xb>>yb; if (xa>=xb) CO "Draw" L; elif (abs(ya-yb)-1>(xb-xa-1)) CO "Draw" L; elif ((xa-xb)%2!=0) { int la=max(1,ya-(xb-xa)/2-1); int ra=min(m,ya+(xb-xa)/2+1); int lb=max(1,yb-(xb-xa)/2); int rb=min(m,yb+(xb-xa)/2); if (la<=lb&&ra>=rb) CO "Alice" L; else CO "Draw" L; } else { int la=max(1,ya-(xb-xa)/2); int ra=min(m,ya+(xb-xa)/2); int lb=max(1,yb-(xb-xa)/2); int rb=min(m,yb+(xb-xa)/2); if (lb<=la&&rb>=ra) CO "Bob" L; else CO "Draw" L; } } return0; }