結果
| 問題 | No.506 限られたジャパリまん | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-12-25 16:32:28 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 328 ms / 2,000 ms | 
| コード長 | 1,845 bytes | 
| コンパイル時間 | 1,466 ms | 
| コンパイル使用メモリ | 111,048 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-28 04:21:35 | 
| 合計ジャッジ時間 | 3,546 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 25 | 
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.bigint;    // BigInt
import std.bitmanip;  // BitArray
const mod = 10^^9+7;
void main()
{
  auto rd = readln.split.to!(int[]), h = rd[0], w = rd[1], k = rd[2], p = rd[3];
  struct Friend { int x, y; string name; }
  auto f = new Friend[](k);
  foreach (i; 0..k) {
    auto rd2 = readln.split;
    f[i] = Friend(rd2[0].to!int, rd2[1].to!int, rd2[2]);
  }
  auto maxR = BigInt(0), maxI = 0;
  foreach (i; 0..1<<k) {
    if (i.popcnt != p) continue;
    auto fm = new bool[][](h+1, w+1);
    foreach (j; 0..k)
      if (!i.bitTest(j)) fm[f[j].x][f[j].y] = true;
    auto rm = new BigInt[][](h+1, w+1);
    rm[0][0] = 1;
    foreach (x; 0..h+1)
      foreach (y; 0..w+1) {
        if (fm[x][y]) continue;
        if (x > 0) rm[x][y] += rm[x-1][y];
        if (y > 0) rm[x][y] += rm[x][y-1];
      }
    if (rm[h][w] > maxR) {
      maxR = rm[h][w];
      maxI = i;
    }
  }
  writeln(maxR % mod);
  foreach (j; 0..k)
    if (maxI.bitTest(j))
      writeln(f[j].name);
}
pragma(inline) {
  pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; }
  pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); }
  pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); }
  pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); }
  pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); }
  pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); }
  pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); }
  import core.bitop;
  pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); }
  pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); }
  pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); }
}
            
            
            
        