結果
問題 |
No.506 限られたジャパリまん
|
ユーザー |
|
提出日時 | 2017-04-21 22:40:46 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,434 bytes |
コンパイル時間 | 2,950 ms |
コンパイル使用メモリ | 123,280 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-28 04:08:54 |
合計ジャッジ時間 | 3,958 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 WA * 12 |
ソースコード
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]); } int 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 int[][](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]) % MOD; if (c > 0) dp[r][c] = (dp[r][c] + dp[r][c-1]) % MOD; } } if (dp[H][W] > maxval) { maxval = dp[H][W]; maxf = i; } } if (maxval == 0) { writeln(0); } else { writeln(maxval); foreach (i; 0..K) { if (maxf & (1 << i)) writeln(F[i].name); } } }