結果

問題 No.177 制作進行の宮森あおいです!
ユーザー yaoshimaxyaoshimax
提出日時 2015-05-06 20:50:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 2,100 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 90,300 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 07:14:59
合計ジャッジ時間 1,760 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

#define GRAPH_SIZE 2510

struct edge{ int to, cap, rev; };
vector<edge> graph[GRAPH_SIZE];
bool used[GRAPH_SIZE];

void addedge( int from, int to, int cap ){
  //枝を追加する。逆向きには容量0の真逆な枝を追加しておく。
  graph[from].push_back( (edge){to,cap,(int)graph[to].size()} );
  graph[to].push_back( (edge){from,0, (int)graph[from].size()-1} );
  return;
}

int dfs( int v, int t, int f ){
  if( v==t ) return f;
  used[v]=true;
  for( int i = 0 ; i < (int)graph[v].size(); i++){
    edge &e = graph[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;
        graph[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,INT_MAX/2);
    if( f == 0 ) return flow;
    flow += f;
  }
}

int main(){
   int W,N;
   cin >> W>>N;
   int J[N];
   for( int i = 0 ; i < N ; i++ ) cin>>J[i];
   for( int i = 0 ; i <N; i++)  addedge(0,i+1,J[i]);
   int M;
   cin >> M;
   int C[M];
   for( int i=0 ; i<M; i++ ) cin>>C[i];
   for( int i=0;i<M;i++)addedge(N+1+i,N+M+1,C[i]);
   for( int j = 0 ; j <M; j++ ){
      bool ok[N];
      memset(ok,true,sizeof(ok));
      int Q;
      cin >> Q;
      for( int i = 0 ; i < Q; i++ ){
         int x;
         cin >> x;
         ok[x-1]=false;
      }
      for( int i = 0 ; i < N; i++ ){
         if(ok[i]) addedge(i+1,N+1+j,1000000);
      }
   }
   int f=max_flow(0,N+M+1);
   //printf("%d\n",f);
   if(f>=W){
      printf("SHIROBAKO\n");
   }
   else printf("BANSAKUTSUKITA\n");
   return 0;

}




0