結果

問題 No.179 塗り分け
ユーザー takeya_okino
提出日時 2019-08-03 23:26:13
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,450 bytes
コンパイル時間 2,140 ms
コンパイル使用メモリ 76,888 KB
実行使用メモリ 54,360 KB
最終ジャッジ日時 2024-07-06 12:47:19
合計ジャッジ時間 8,738 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 3
other AC * 16 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    int[] grid = new int[h * w];
    for(int i = 0; i < h; i++) {
      String s = sc.next();
      for(int j = 0; j < w; j++) {
        if(s.charAt(j) == '#') {
          grid[w * i + j] = 1; 
        }
      }
    }
    int pp = 0;
    // 1が黒、2が青、3が赤
    for(int s = 0; s < w; s++) {
      for(int t = 0; t < h; t++) {
      int[] g = grid;
      int p = 0;
      int c = 0;
        for(int i = 0; i < h; i++) {
          for(int j = 0; j < w; j++) {
            int a = i * w + j;
            if(g[a] == 1) {
              if(((j + s) < w) && ((i + t) < h)) {
                int b = (i + t) * w + (j + s);
                if(c == 0) {
                  g[a] = 2;
                  if(g[b] == 1) {
                    g[b] = 3;
                  } else {
                    p++;
                  }
                } else {
                  g[a] = 3;
                  if(g[b] == 1) {
                    g[b] = 2;
                  } else {
                    p++;
                  }
                }
                c = 1 - c;
              } else {
                p++;
              }
            }
          }
        }
        if(p == 0) pp++;
      }
    }
    String ans = "NO";
    if(pp > 0) ans = "YES";
    System.out.println(ans);
  }
}
0