結果

問題 No.179 塗り分け
ユーザー notetonous
提出日時 2016-06-16 01:25:19
言語 C90
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,218 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 22,144 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-03 03:26:16
合計ジャッジ時間 1,319 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 29 WA * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:40:27: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[50]’ [-Wformat=]
   40 |   for(i=0;i<H;i++)scanf("%s",&s[i]);
      |                          ~^  ~~~~~
      |                           |  |
      |                           |  char (*)[50]
      |                           char *
main.c:39:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |   scanf("%d %d",&H,&W);
      |   ^~~~~~~~~~~~~~~~~~~~
main.c:40:19: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |   for(i=0;i<H;i++)scanf("%s",&s[i]);
      |                   ^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
int H,W;
char s[50][50];
char tmp[50][50];

int color(int di,int dj){
  int i,j;
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      if(tmp[i][j]=='#'){
	if(tmp[i+di][j+dj]=='#' && 0 <= i+di && i+di<H && 0<=j+dj && j+dj<W)tmp[i][j]=tmp[i+di][j+dj]='.';
	else return 0;
      }
    }
  }
  return 1;
}
void init(){
  int i,j;
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      tmp[i][j]=s[i][j];
    }
  }
}
void print(){
  int i,j;
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      printf("%c",tmp[i][j]);
    }
    printf("\n");
  }
}
int main(){
  int i,j;
  int di,dj;
  int flag=0;
  scanf("%d %d",&H,&W);
  for(i=0;i<H;i++)scanf("%s",&s[i]);
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      if(s[i][j]=='#')flag=1;
    }
  }
  if(flag=0){
    printf("NO\n");
    return 0;
  }
  init();
  di=0;
  for(dj=1;dj<W;dj++){
    //printf("%d %d\n",di,dj);
    if(color(di,dj)==1){
      printf("YES\n");
      //print();
      return 0;
    }
    //print();
    init();
  }

  for(di=1;di<H;di++){
    for(dj=-W+1;dj<W;dj++){
      // printf("%d %d\n",di,dj);
      if(color(di,dj)==1){
	printf("YES\n");
	//	print();
	return 0;
      }
      // print();
      init();
    }
  }
  printf("NO\n");
  return 0;
}
0