結果

問題 No.179 塗り分け
ユーザー crazybbb3crazybbb3
提出日時 2016-12-07 21:50:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 188 ms / 3,000 ms
コード長 2,901 bytes
コンパイル時間 2,602 ms
コンパイル使用メモリ 74,272 KB
実行使用メモリ 53,264 KB
最終ジャッジ日時 2023-09-30 20:52:35
合計ジャッジ時間 8,325 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,564 KB
testcase_01 AC 46 ms
49,632 KB
testcase_02 AC 45 ms
49,508 KB
testcase_03 AC 45 ms
49,664 KB
testcase_04 AC 46 ms
49,856 KB
testcase_05 AC 78 ms
51,736 KB
testcase_06 AC 56 ms
50,740 KB
testcase_07 AC 130 ms
52,408 KB
testcase_08 AC 82 ms
52,540 KB
testcase_09 AC 106 ms
52,544 KB
testcase_10 AC 87 ms
52,868 KB
testcase_11 AC 74 ms
52,236 KB
testcase_12 AC 88 ms
52,876 KB
testcase_13 AC 47 ms
49,480 KB
testcase_14 AC 46 ms
49,876 KB
testcase_15 AC 44 ms
49,560 KB
testcase_16 AC 44 ms
50,044 KB
testcase_17 AC 46 ms
49,512 KB
testcase_18 AC 82 ms
52,252 KB
testcase_19 AC 63 ms
51,652 KB
testcase_20 AC 84 ms
52,292 KB
testcase_21 AC 156 ms
53,264 KB
testcase_22 AC 188 ms
53,068 KB
testcase_23 AC 86 ms
52,220 KB
testcase_24 AC 108 ms
52,748 KB
testcase_25 AC 89 ms
52,508 KB
testcase_26 AC 96 ms
52,396 KB
testcase_27 AC 85 ms
52,676 KB
testcase_28 AC 88 ms
52,556 KB
testcase_29 AC 82 ms
52,872 KB
testcase_30 AC 91 ms
52,520 KB
testcase_31 AC 89 ms
52,672 KB
testcase_32 AC 88 ms
52,092 KB
testcase_33 AC 82 ms
52,464 KB
testcase_34 AC 87 ms
52,832 KB
testcase_35 AC 83 ms
52,388 KB
testcase_36 AC 45 ms
49,732 KB
testcase_37 AC 46 ms
49,580 KB
testcase_38 AC 46 ms
49,448 KB
testcase_39 AC 45 ms
49,452 KB
testcase_40 AC 47 ms
49,500 KB
testcase_41 AC 46 ms
49,540 KB
testcase_42 AC 47 ms
49,560 KB
testcase_43 AC 56 ms
50,612 KB
testcase_44 AC 65 ms
51,684 KB
testcase_45 AC 48 ms
49,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int h = ni();
        int w = ni();
        String[] s = nsa(h);

        boolean[][] used = new boolean[h][w];
        for (int i = 1 - h; i < h; i++) {
            outside:
            for (int j = 1 - w; j < w; j++) {
                if (i == 0 && j == 0) {
                    continue;
                }

                for (int k = 0; k < h; k++) {
                    Arrays.fill(used[k], false);
                }

                boolean flg = false;

                for (int k = 0; k < h; k++) {
                    for (int l = 0; l < w; l++) {
                        if (s[k].charAt(l) == '#' && !used[k][l]) {
                            if (k + i < 0 || l + j < 0 || k + i > h - 1 || l + j > w - 1) {
                                continue outside;
                            }
                            if (s[k + i].charAt(l + j) == '.' || used[k + i][l + j]) {
                                continue outside;
                            }
                            used[k + i][l + j] = true;
                            flg = true;
                        }
                    }
                }

                if (flg) {
                    out.println("YES");
                    return;
                }
            }
        }

        out.println("NO");
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}
0