結果

問題 No.177 制作進行の宮森あおいです!
ユーザー yuto_okayamayuto_okayama
提出日時 2019-01-18 00:48:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,738 bytes
コンパイル時間 1,355 ms
コンパイル使用メモリ 157,040 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-14 02:06:54
合計ジャッジ時間 2,469 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

int w, n, m;
vector<tuple<int, int, int>> g[202];
bool used[202];

int dfs(int v, int t, int f)
{
  if(v == t) return f;
  used[v] = true;

  for(auto &u : g[v]){
    int to, cap, rev;
    tie(to, cap, rev) = u;
    if(!used[to] and cap > 0){
      int ff = dfs(to, t, min(f, cap));
      if(ff > 0){
        get<1>(u) -= ff;
        get<1>(g[to][rev]) += ff;
        return ff;
      }
    }
  }

  return 0;
}

int maxflow(int s, int t)
{
  int flow = 0;
  while(1){
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, inf);
    if(f == 0) return flow;
    flow += f;
  }
}

void add_edge(int from, int to, int cap)
{
  g[from].pb(mt(to, cap, g[to].size()));
  g[to].pb(mt(from, 0, g[from].size()-1));
}

int main()
{
  cin >> w >> n;

  repi(i, 1, n+1){
    add_edge(0, i, inf);

    int j;
    cin >> j;
    add_edge(i, i+50, j);
  }

  cin >> m;

  repi(i, 1, m+1){
    int c;
    cin >> c;
    add_edge(100+i, 150+i, c);
    add_edge(150+i, 201, inf);
  }

  repi(i, 1, m+1){
    int q;
    cin >> q;

    vi x(q);
    rep(j, q) cin >> x[j];

    int k = 0;
    repi(j, 1, n+1){
      if(j == x[k]) k++;
      else add_edge(50+j, 100+i, inf);
    }
  }

  if(maxflow(0, 201) >= w) cout << "SHIROBAKO" << endl;
  else cout << "BANSAKUTSUKITA" << endl;

  return 0;
}
0