結果
問題 | No.179 塗り分け |
ユーザー |
|
提出日時 | 2020-02-19 14:35:52 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 265 ms / 3,000 ms |
コード長 | 1,459 bytes |
コンパイル時間 | 2,606 ms |
コンパイル使用メモリ | 77,992 KB |
実行使用メモリ | 57,120 KB |
最終ジャッジ日時 | 2024-07-23 15:11:48 |
合計ジャッジ時間 | 11,055 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 40 |
ソースコード
import java.util.ArrayDeque; import java.util.Arrays; import java.util.Scanner; class Main { public static void main(String[] args) throws Exception { new Main().run(); } void solve(int H,int W,char[][] m) { for(int dh=0;dh<H;++dh) { for(int dw=0;dw<W;++dw) { if(dh==0&&dw==0)continue; boolean flag=true; int[][] rec=new int[H][W]; for(int h=0;h<H;++h) { for(int w=0;w<W;++w) { if(m[h][w]=='.')continue; if(rec[h][w]!=0)continue; int nh=h+dh; int nw=w+dw; if(nh>=H||nw>=W) { flag=false; continue; } if(rec[nh][nw]==2) { flag=false; continue; } flag&=m[nh][nw]=='#'; rec[h][w]=1; rec[nh][nw]=2; } } if(flag) { System.out.println("YES"); System.exit(0); } } } } void run() { Scanner sc=new Scanner(System.in); int H=sc.nextInt(); int W=sc.nextInt(); char[][] m=new char[H][W]; boolean all=true; for(int i=0;i<H;++i) { m[i]=sc.next().toCharArray(); for(int j=0;j<m[i].length;++j)all&=m[i][j]=='.'; } if(all) { System.out.println("NO"); return; } solve(H,W,m); { for(int h=0;h<H;++h) { int s=0; int t=W-1; while(s<t) { m[h][s]^=m[h][t];m[h][t]^=m[h][s];m[h][s]^=m[h][t]; ++s;--t; } } } solve(H,W,m); System.out.println("NO"); } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }