結果
| 問題 | No.179 塗り分け |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-06-18 16:57:44 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,103 bytes |
| 記録 | |
| コンパイル時間 | 3,738 ms |
| コンパイル使用メモリ | 84,104 KB |
| 実行使用メモリ | 47,988 KB |
| 最終ジャッジ日時 | 2026-06-18 16:57:56 |
| 合計ジャッジ時間 | 8,507 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 37 WA * 2 RE * 1 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class No179 {
public static void main(String[] args) throws IOException {
String[] text = readStr();
int h = Integer.parseInt(text[0].split(" ")[0]);
int w = Integer.parseInt(text[0].split(" ")[1]);
String[][] strings = new String[h][w];
for(int i = 0;i < h;i++) {
strings[i]= text[i+1].split("");
}
int sh = -1,sw = -1;
for(int i = 0;i < h;i++) {
for(int j = 0;j < w;j++) {
if("#".equals(strings[i][j])){
sh = i;
sw = j;
break;
}
}
if(Math.min(sh, sw)>=0){
break;
}
}
boolean ans = false;
for(int i = 0;i < h;i++) {
for(int j = -1*w+1;j < w;j++) {
if(i == 0 && j <= 0) {
continue;
}
ans = checkPaint(i, j, strings, sh, sw);
if(ans) {
break;
}
}
if(ans) {
break;
}
}
if(ans) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
public static boolean checkPaint(int h,int w,String[][] str,int sh,int sw) {
boolean ans = true;
String[][] strings = new String[str.length][str[0].length];
for (int i = 0;i < str.length;i++) {
for(int j = 0;j < str[0].length;j++) {
strings[i][j]= str[i][j];
}
}
for(int i = sh;i < strings.length;i++) {
for(int j = sw;j < strings[0].length;j++) {
if("#".equals(strings[i][j])){
if(i + h >= strings.length || j + w < 0 || j + w >= strings[0].length) {
ans = false;
break;
}
if(!"#".equals(strings[i+h][j+w])) {
ans = false;
break;
}
strings[i+h][j+w] = ".";
}
}
if(!ans) {
break;
}
}
return ans;
}
public static String[] readStr() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<>();
do {
list.add(br.readLine());
}while(br.ready());
br.close();
String[] text = new String[list.size()];
list.toArray(text);
return text;
}
}