#include #include #include int H, W; char str[100]; char board[100][100]; char shiftedboard[100][100]; char tmpboard[100][100]; void copyboard(char src[][100], char dst[][100]){ for(int x = 0; x < 100; x++){ for(int y = 0; y < 100; y++){ dst[x][y] = src[x][y]; } } } int countboard(char b[][100], int num){ int cnt=0; for(int x = 0; x < 2*W; x++){ for(int y = 0; y < 2*H; y++){ if(b[x][y]==num) cnt++; } } return cnt; } void printboard(char b[][100]){ /* for(int y=0; y < H; y++){ for(int x =0; x < W; x++){ printf("%d",b[x][y]); }puts(""); } puts("--"); */ } void shift(int shift_x, int shift_y){ assert(shift_x + W < 100 && shift_y + H < 100); memset(shiftedboard,0,sizeof(shiftedboard)); for(int x = 0; x < W; x++){ for(int y = 0; y < H; y++){ shiftedboard[x][y] += board[x][y]; shiftedboard[x+shift_x][y+shift_y] += board[x][y]; } } printboard(shiftedboard); } int main(void){ scanf("%d %d",&H,&W); memset(board,0,sizeof(board)); memset(tmpboard,0,sizeof(tmpboard)); for(int i = 0; i < H ; i++){ scanf("%s",str); for(int j = 0; j < W; j++){ board[j][i] = (str[j]=='#')? 1 : 0; } } int cnt_one = countboard(board, 1); printboard(board); int shift_x, shift_y; for(shift_x = 0; shift_x < W; shift_x++){ for(shift_y = 0; shift_y < H; shift_y++){ shift(shift_x,shift_y); //printf("count2=%d,cnt_one=%d\n",countboard(shiftedboard,2),cnt_one); if(countboard(shiftedboard,2) * 2 == cnt_one){ copyboard(board,tmpboard); for(int x = 0; x < W*2; x++){ for(int y = 0; y < H*2; y++){ if(shiftedboard[x][y]==2){ tmpboard[x-shift_x][y-shift_y] += 1; tmpboard[x][y] = 2; } } } //printf("candidate shiftx=%d shifty=%d\n",shift_x,shift_y); printboard(tmpboard); if(countboard(tmpboard,2) == cnt_one){ puts("YES"); return 0; } } } } puts("NO"); }