結果

問題 No.506 限られたジャパリまん
ユーザー nebukuro09nebukuro09
提出日時 2017-04-21 22:49:18
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 462 ms / 2,000 ms
コード長 1,434 bytes
コンパイル時間 1,315 ms
コンパイル使用メモリ 108,892 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 12:51:12
合計ジャッジ時間 4,610 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 7 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 462 ms
4,380 KB
testcase_09 AC 177 ms
4,376 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 457 ms
4,380 KB
testcase_12 AC 277 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 348 ms
4,376 KB
testcase_17 AC 15 ms
4,376 KB
testcase_18 AC 17 ms
4,380 KB
testcase_19 AC 43 ms
4,376 KB
testcase_20 AC 115 ms
4,376 KB
testcase_21 AC 31 ms
4,376 KB
testcase_22 AC 140 ms
4,376 KB
testcase_23 AC 89 ms
4,376 KB
testcase_24 AC 11 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;

immutable int MOD = 10^^9+7;
alias Tuple!(int, "r", int, "c", string, "name") Friend;


void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto K = s[2];
    auto P = s[3];
    auto F = new Friend[](K);
    foreach (i; 0..K) {
        auto t = readln.split;
        F[i] = Friend(t[0].to!int, t[1].to!int, t[2]);
    }

    BigInt maxval = 0;
    int maxf = 0;
    foreach (i; 0..2^^K) {
        if (i.popcnt != P) continue;
        auto B = new bool[][](H+1, W+1);
        foreach (j; 0..K) {
            if (!(i & (1 << j))) {
                B[F[j].r][F[j].c] = true;
            }
        }

        auto dp = new BigInt[][](H+1, W+1);
        dp[0][0] = 1;
        foreach (r; 0..H+1) {
            foreach (c; 0..W+1) {
                if (B[r][c]) continue;
                if (r > 0) dp[r][c] = (dp[r][c] + dp[r-1][c]);
                if (c > 0) dp[r][c] = (dp[r][c] + dp[r][c-1]);
            }
        }

        if (dp[H][W] > maxval) {
            maxval = dp[H][W];
            maxf = i;
        }
    }

    if (maxval == 0) {
        writeln(0);
    }
    else {
        writeln(maxval % MOD);
        foreach (i; 0..K) {
            if (maxf & (1 << i)) writeln(F[i].name);
        }
    }
}
0