結果

問題 No.177 制作進行の宮森あおいです!
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-09-07 00:45:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,694 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 74,656 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 17:02:44
合計ジャッジ時間 1,214 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 5 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 11 ms
6,940 KB
testcase_10 AC 17 ms
6,940 KB
testcase_11 AC 17 ms
6,940 KB
testcase_12 AC 8 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In member function ‘void Flow::add_edge(int, int, int)’:
main.cpp:20:61: warning: narrowing conversion of ‘((Flow*)this)->Flow::G[to].std::vector<Flow::edge>::size()’ from ‘std::vector<Flow::edge>::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing]
   20 |                 G[from].push_back((edge){to, cap, G[to].size()});//from -> to
      |                                                   ~~~~~~~~~~^~
main.cpp:21:64: warning: narrowing conversion of ‘(((Flow*)this)->Flow::G[from].std::vector<Flow::edge>::size() - 1)’ from ‘std::vector<Flow::edge>::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing]
   21 |                 G[to].push_back((edge){from, 0, G[from].size() - 1});//to -> from
      |                                                 ~~~~~~~~~~~~~~~^~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;
const int MAX_V = 20000;

struct Flow{
	struct edge{
		int to, cap, rev;
	};
	vector<edge> G[MAX_V];//隣接リスト
	bool used[MAX_V];

	void add_edge(int from, int to, int cap){
		G[from].push_back((edge){to, cap, G[to].size()});//from -> to
		G[to].push_back((edge){from, 0, G[from].size() - 1});//to -> from
	}

	//増加パスを探す
	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;
	}
	//sからtへの最大流
	int max_flow(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;
		}
	}
};

int j[10010], c[10010];
set<int> x[55];
int main(void){
	int w; cin >> w;
	int n; cin >> n;
	rep(i, n) cin >> j[i];
	int m; cin >> m;
	rep(i, m) cin >> c[i];
	rep(i, m){
		int q; cin >> q;
		rep(j, q){
			int tmp; cin >> tmp;
			tmp--;
			x[i].insert(tmp);
		}
	}
	Flow mf;
	//s = 0; t = 200
	rep(i, n) mf.add_edge(0, i + 1, j[i]);//s -> 作画
	rep(i, m) mf.add_edge(100 + i, 200, c[i]);//監督 -> t
	rep(v, m){
		rep(u, n){
			if(x[v].count(u) == 0){//u -> vが許される
				mf.add_edge(u + 1, v + 100, INF);
			}
		}
	}

	ll ans = mf.max_flow(0, 200);
	if(ans >= w) printf("SHIROBAKO\n");
	else printf("BANSAKUTSUKITA\n");
	return 0;
}
0