結果

問題 No.640 76本のトロンボーン
ユーザー nebukuro09nebukuro09
提出日時 2018-12-10 13:15:24
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,569 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 107,824 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 21:31:19
合計ジャッジ時間 1,672 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 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, core.stdc.string;

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

    int ans = 0;
    int[] rr = [0, 0, N-1, 0];
    int[] cc = [0, 0, 0, N-1];
    int[] dr = [0, 1, 0, 1];
    int[] dc = [1, 0, 1, 0];

    foreach (mask; 0..3^^4) {
        int tmp = 0;
        bool ok = true;
        auto B = A.map!(a => a.dup).array;
        foreach (i; 0..4) {
            int sr = rr[i];
            int sc = cc[i];
            int k = mask % 3;
            mask /= 3;
            if (k == 1) {
                sr += dr[i];
                sc += dc[i];
            } else if (k == 2) {
                continue;
            }
            tmp += 1;
            foreach (j; 0..N-1) {
                if (B[sr][sc] == '#') {
                    ok = false;
                    break;
                }
                B[sr][sc] = '#';
                sr += dr[i];
                sc += dc[i];
            }
        }
        if (!ok) continue;
        int row = 0;
        int col = 0;
        foreach (i; 1..N-1) {
            row += B[i][1..N-1].map!(x => x == '.').all && (B[i][0] == '.' || B[i][N-1] == '.');
        }
        foreach (j; 1..N-1) {
            col += iota(1, N-1).map!(i => A[i][j] == '.').all && (B[0][j] == '.' || B[N-1][j] == '.');
        }
        ans = max(ans, tmp + max(row, col));
    }

    ans.writeln;
}
0