結果

問題 No.177 制作進行の宮森あおいです!
ユーザー ikdikd
提出日時 2018-02-07 22:48:38
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,908 bytes
コンパイル時間 686 ms
コンパイル使用メモリ 90,764 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 18:37:37
合計ジャッジ時間 1,643 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 16 ms
4,376 KB
testcase_11 AC 14 ms
4,380 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class maxFlow{
  import std.typecons, std.conv, std.algorithm, std.stdio;
  alias T=int; // type of flow
  alias Edge=Tuple!(int, "to", int, "rev", T, "cap");
  Edge[][] g;
  bool[] vis;
  auto inf=(1_000_000_000).to!(T);

  this(int sz){
    g.length=sz;
    vis.length=sz;
  }

  void addEdge(int from, int to, T cap){
    g[from]~=Edge(to, (g[to].length).to!(int), cap);
    g[to]~=Edge(from, (g[from].length-1).to!(int), (0).to!(T));
  }

  T flow(int i, T curf, int sink){
    if(i==sink) return curf;
    vis[i]=true;
    foreach(ref e; g[i]){
      if(vis[e.to] || e.cap==0) continue;
      auto tmpf=flow(e.to, min(curf, e.cap), sink);
      if(tmpf>0){
        e.cap-=tmpf;
        g[e.to][e.rev].cap+=tmpf;
        return tmpf;
      }
    }
    return 0;
  }

  T ford(int source, int sink){
    auto maxf=(0).to!(T);
    while(true){
      fill(vis, false);
      auto f=flow(source, inf, sink);
      if(f>0) maxf+=f;
      else return maxf;
    }
  }
}

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int w; rd(w);
  int n; rd(n);
  auto js=readln.split.to!(int[]);
  int m; rd(m);
  auto cs=readln.split.to!(int[]);

  auto mf=new maxFlow(n+m+2);
  auto s=n+m, t=n+m+1;
  foreach(int i; 0..n) mf.addEdge(s, i, js[i]);
  foreach(int j; 0..m) mf.addEdge(j+n, t, cs[j]);
  const inf=1_000_000;
  foreach(int j; 0..m){
    auto args=readln.split.to!(int[]);
    for(int idx=1, i=0; idx<=args.length; idx++, i++){
      if(idx==args.length){
        while(i<n) mf.addEdge(i, j+n, inf), i++;
        break;
      }else{
        while(i<(args[idx]-1)) mf.addEdge(i, j+n, inf), i++;
      }
    }
  }

  if(mf.ford(s, t)>=w){
    writeln("SHIROBAKO");
  }else{
    writeln("BANSAKUTSUKITA");
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
0