結果

問題 No.640 76本のトロンボーン
ユーザー nebukuro09nebukuro09
提出日時 2018-01-26 23:00:56
言語 D
(dmd 2.105.2)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,721 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 108,380 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 18:24:50
合計ジャッジ時間 1,421 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const long MOD = 10^^9 + 7;

void main() {
    auto N = readln.chomp.to!int;
    auto A = N.iota.map!(_ => readln.chomp).array;

    auto tate1 = new bool[](N);
    auto tate2 = new bool[](N);
    auto yoko1 = new bool[](N);
    auto yoko2 = new bool[](N);

    foreach (i; 0..N) {
        tate1[i] = iota(N-1).map!(j => A[j][i] == '.').all;
        tate2[i] = iota(1,N).map!(j => A[j][i] == '.').all;
        yoko1[i] = iota(N-1).map!(j => A[i][j] == '.').all;
        yoko2[i] = iota(1,N).map!(j => A[i][j] == '.').all;
    }

    int ans = 0;

    foreach (mask; 0..2^^4) {
        auto hoge = new bool[4];
        foreach (i; 0..4) {
            hoge[i] = (mask & (1 << i)) != 0;
        }
        hoge[0] &= tate1[0];
        hoge[1] &= yoko2[0];
        hoge[2] &= tate2[N-1];
        hoge[3] &= yoko1[N-1];

        int tmp = hoge.sum;
        foreach (i; 1..N-1) {
            if (hoge[0] && !hoge[2]) {
                tmp += yoko2[i];
            } else if (!hoge[0] && hoge[2]) {
                tmp += yoko1[i];
            } else if (!hoge[0] && !hoge[2]) {
                tmp += yoko1[i] || yoko2[i];
            }
        }
        ans = max(ans, tmp);

        tmp = hoge.sum;
        foreach (i; 1..N-1) {
            if (hoge[1] && !hoge[3]) {
                tmp += tate2[i];
            } else if (!hoge[1] && hoge[3]) {
                tmp += tate1[i];
            } else if (!hoge[1] && !hoge[3]) {
                tmp += tate1[i] || tate2[i];
            }
        }
        ans = max(ans, tmp);
    }


    foreach (mask; 0..2^^4) {
        auto hoge = new bool[4];
        foreach (i; 0..4) {
            hoge[i] = (mask & (1 << i)) != 0;
        }
        hoge[0] &= tate2[0];
        hoge[1] &= yoko1[0];
        hoge[2] &= tate1[N-1];
        hoge[3] &= yoko2[N-1];

        int tmp = hoge.sum;
        foreach (i; 1..N-1) {
            if (hoge[0] && !hoge[2]) {
                tmp += yoko2[i];
            } else if (!hoge[0] && hoge[2]) {
                tmp += yoko1[i];
            } else if (!hoge[0] && !hoge[2]) {
                tmp += yoko1[i] || yoko2[i];
            }
        }
        ans = max(ans, tmp);

        tmp = hoge.sum;
        foreach (i; 1..N-1) {
            if (hoge[1] && !hoge[3]) {
                tmp += tate2[i];
            } else if (!hoge[1] && hoge[3]) {
                tmp += tate1[i];
            } else if (!hoge[1] && !hoge[3]) {
                tmp += tate1[i] || tate2[i];
            }
        }
        ans = max(ans, tmp);
    }

    ans.writeln;
}
0