結果
問題 | No.506 限られたジャパリまん |
ユーザー |
|
提出日時 | 2017-04-21 22:49:18 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 406 ms / 2,000 ms |
コード長 | 1,434 bytes |
コンパイル時間 | 2,712 ms |
コンパイル使用メモリ | 125,380 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-28 04:10:09 |
合計ジャッジ時間 | 4,317 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 |
ソースコード
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);}}}