結果

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

テストケース

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

	//s = 0; t = 200
	rep(i, n) add_edge(0, i + 1, j[i]);//s -> 作画
	rep(i, m) add_edge(100 + i, 200, c[i]);//監督 -> t
	rep(v, m){
		rep(u, n){
			if(x[v].count(u) == 0){//u -> vが許される
				add_edge(u + 1, v + 100, INF);
			}
		}
	}

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