結果

問題 No.177 制作進行の宮森あおいです!
ユーザー nenuonnenuon
提出日時 2017-07-30 01:51:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,944 bytes
コンパイル時間 918 ms
コンパイル使用メモリ 94,208 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 03:50:43
合計ジャッジ時間 1,663 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
const int inf = 1e9;
// 最大流、最小カット!!!!
// フォード・ファルカーソン法
const int MAX_V = 110;
// 行き先、容量、逆辺
struct edge {
  int to, cap, rev;
  edge(int t, int c, int r) {
    to = t, cap = c, rev = r;
  }
};
vector<vector<edge> > G(MAX_V);
bool used[MAX_V];
// fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from, int to, int cap) {
  G[from].push_back(edge(to, cap, G[to].size()));
  G[to].push_back(edge(from, 0, G[from].size()-1));
}
// 増加パスをdfsで探す
int dfs(int v, int t, int f) {
  if(v == t) return f;
  used[v] = true;
  for(edge &e : G[v]) {
    if(!used[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if(d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s, int t) {
  int flow = 0;
  for(;;) {
    FOR(i,0,MAX_V) used[i] = 0;
    int f = dfs(s, t, 1e9);
    if(f == 0) return flow;
    flow += f;
  }
}
int main()
{
  int N, W, M;
  cin >> W >> N;
  int J[N]; FOR(i,0,N) cin >> J[i];
  cin >> M;
  int C[M]; FOR(i,0,M) cin >> C[i];
  bool ng[111][111];
  FOR(i,0,111) FOR(j,0,111) ng[i][j] = false;
  FOR(i,N+1,N+M+1) {
    int Q; cin >> Q;
    FOR(j,0,Q) {
      int in; cin >> in;
      ng[in][i] = true;
    }
  }
  FOR(i,1,N+1) add_edge(0, i, J[i-1]);
  FOR(i,N+1,N+M+1) add_edge(i, N+M+1, C[i-N-1]);
  FOR(i,1,N+1) {
    FOR(j,N+1,N+M+1) {
      if(!ng[i][j]) add_edge(i, j, inf);
    }
  }
  if(max_flow(0, N+M+1) >= W) puts("SHIROBAKO");
  else puts("BANSAKUTSUKITA");
  return 0;
}
0