結果

問題 No.179 塗り分け
ユーザー nanaenanae
提出日時 2017-12-11 21:41:22
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 218 ms / 3,000 ms
コード長 1,836 bytes
コンパイル時間 765 ms
コンパイル使用メモリ 97,924 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 17:28:37
合計ジャッジ時間 5,397 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 20 ms
4,380 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 126 ms
4,380 KB
testcase_09 AC 120 ms
4,380 KB
testcase_10 AC 79 ms
4,380 KB
testcase_11 AC 67 ms
4,380 KB
testcase_12 AC 139 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 71 ms
4,376 KB
testcase_19 AC 68 ms
4,380 KB
testcase_20 AC 130 ms
4,380 KB
testcase_21 AC 129 ms
4,380 KB
testcase_22 AC 129 ms
4,376 KB
testcase_23 AC 77 ms
4,376 KB
testcase_24 AC 134 ms
4,380 KB
testcase_25 AC 70 ms
4,376 KB
testcase_26 AC 88 ms
4,380 KB
testcase_27 AC 181 ms
4,380 KB
testcase_28 AC 108 ms
4,380 KB
testcase_29 AC 208 ms
4,380 KB
testcase_30 AC 143 ms
4,376 KB
testcase_31 AC 218 ms
4,380 KB
testcase_32 AC 120 ms
4,384 KB
testcase_33 AC 198 ms
4,376 KB
testcase_34 AC 121 ms
4,380 KB
testcase_35 AC 208 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 9 ms
4,380 KB
testcase_44 AC 27 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.d(14): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`

ソースコード

diff #

import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int h, w;
    scan(h, w);

    auto map = new int[][](h, w);
    int kuro = h*w;

    foreach (i ; 0 .. h) {
        string s = readln.chomp;
        foreach (int j, ch; s) {
            if (ch == '.') {
                map[i][j] = 1;
                kuro--;
            }
        }
    }

    if (kuro==0){
        writeln("NO");
        return;
    }

    foreach (x ; -h .. h) {
        foreach (y ; -w .. w) {
            if (x == 0 && y == 0) continue;

            bool ok = 1;
            auto m = new int[][](h, w);
            iota(h).each!(i => m[i] = map[i].dup);

            foreach (i ; 0 .. h) {
                foreach (j ; 0 .. w) {
                    if (m[i][j]) continue;

                    m[i][j] = 2;

                    if (i + x < 0 || i + x >= h || j + y < 0 || j + y >= w || m[i+x][j+y]) {
                        ok = 0;
                    }
                    else {
                        m[i + x][j + y] = 3;
                    }
                }
            }

            if (ok) {
                debug {
                    writefln("%(%(%s %)\n%)", m);
                    writeln(x, " ", y);
                }
                writeln("YES");
                return;
            }
        }
    }

    writeln("NO");
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
0