結果

問題 No.177 制作進行の宮森あおいです!
ユーザー たこしたこし
提出日時 2015-06-06 17:59:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 2,648 bytes
コンパイル時間 681 ms
コンパイル使用メモリ 94,708 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 19:32:25
合計ジャッジ時間 1,536 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF_MIN 100000000
#define INF 1145141919
#define INF_MAX 2147483647
#define LL_MAX 9223372036854775807
#define EPS 1e-9
#define PI acos(-1)
#define LL long long

using namespace std;

#define MAX_V 110

struct edge{
  int to, cap, rev;
  edge(int _a, int _b, int _c) : to(_a), cap(_b), rev(_c){};
};

vector<edge> G[MAX_V]; //グラフの隣接リスト
bool used[MAX_V]; //DFSですでに調べたかのフラグ

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));
}

int dfs(int v, int t, int f){

  if(v == t)
    return f;

  used[v] = true;

  for(int i = 0; i < G[v].size(); i++){
    edge &e = G[v][i];
    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;
  while(true){
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0)
      return flow;
    flow += f;
  }

}

#define MAX_N 51
#define MAX_M 51

int W, N;
int J[MAX_N];
int M;
int C[MAX_M];
int Q[MAX_M];
int X[MAX_M][MAX_M];

bool checkEdge(int s, int t){

  bool flag = true;

  for(int i = 0; i < Q[t]; i++){
    if(X[t][i] == s+1){
      flag = false;
      break;
    }
  }
  
  return flag;

}

int main(){

  cin >> W;
  cin >> N;

  //宮守から原画マンが処理できるだけの原画容量をもった辺を張る
  for(int i = 0; i < N; i++){
    cin >> J[i];
    add_edge(0, i+1, J[i]);
  }
  
  //作監から宮守に作監が処理出来るだけの容量をもった辺を張る
  cin >> M;
  for(int i = 0; i < M; i++){
    cin >> C[i];
    add_edge(N+i+1, N+M+1, C[i]);
  }

  for(int i = 0; i < M; i++){
    cin >> Q[i];
    for(int j = 0; j < Q[i]; j++){
      cin >> X[i][j];
    }
  }

  //原画マンから作監に辺を貼る
  for(int i = 0; i < N; i++){
    for(int j = 0; j < M; j++){
      if(checkEdge(i, j)){
	//printf("OK: %d %d\n", i, j);
	add_edge(i+1, N+j+1, J[i]);
      }
    }
  }

  if(max_flow(0, N+M+1) >= W)
    cout << "SHIROBAKO" << endl;
  else
    cout << "BANSAKUTSUKITA" << endl;

  return 0;

}
0