結果
問題 | No.179 塗り分け |
ユーザー |
|
提出日時 | 2018-03-26 17:01:00 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,424 bytes |
コンパイル時間 | 293 ms |
コンパイル使用メモリ | 25,472 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 06:49:10 |
合計ジャッジ時間 | 2,420 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 30 WA * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:50:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 50 | scanf("%d %d",&H,&W); | ~~~~~^~~~~~~~~~~~~~~ main.cpp:54:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 54 | scanf("%s",str); | ~~~~~^~~~~~~~~~
ソースコード
#include <stdio.h> #include <string.h> #include <assert.h> 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"); }