結果

問題 No.177 制作進行の宮森あおいです!
ユーザー zerokugizerokugi
提出日時 2015-04-02 23:45:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 4,560 bytes
コンパイル時間 892 ms
コンパイル使用メモリ 118,884 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 03:46:23
合計ジャッジ時間 1,680 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <unordered_map>
#include <iterator>
#include <functional>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

typedef int Weight;
const Weight INF=99999999;
struct Edge{
	int src,dst;
	Weight weight;
	int rev;
	Edge(int f, int t, Weight c,int rev=0):src(f),dst(t),weight(c),rev(rev){}
};
struct Node:public vector<Edge>{};
bool operator<(const Edge &a,const Edge &b){
	return a.weight<b.weight;
}
bool operator>(const Edge &a,const Edge &b){return b<a;}
typedef vector<Node> Graph;
typedef vector<Weight> Array;
typedef vector<vector<Weight> > Matrix;


void add_edge(Graph &G,int s,int t,Weight cap){
	G[s].push_back(Edge(s,t,cap,G[t].size()));
	G[t].push_back(Edge(t,s,0,G[s].size()-1));
}

Weight dfs(const Graph &G, int v, int t, Weight f, const Matrix &cap, Matrix &flow, vector<bool> &visit){
	visit[v]=true;
	if(v == t) return f;
	REP(i, G[v].size()){
		const Edge &e = G[v][i];
		Weight c = cap[v][e.dst] - flow[v][e.dst] + flow[e.dst][v];
		if(!visit[e.dst] && c > 0){
			Weight res = dfs(G, e.dst, t, min(f, c), cap, flow, visit);
			if(res > 0){
				flow[v][e.dst] += res;
				return res;
			}
		}
	}
	return 0;
}
// 最大流を求める。
// Ford-Fulkerson
// O(FE+V^2)
Weight maximum_flow(const Graph &G, int s, int t){
	int V = G.size();
	Matrix cap(V, Array(V,0)); // 容量制限
	Matrix flow(V, Array(V,0)); // 流れている量
	vector<bool> visit(V);
	REP(i,G.size())REP(j,G[i].size()){
		const Edge &e = G[i][j];
		cap[e.src][e.dst] += e.weight;
	}
	Graph network(V); // 辺の候補を求める。(余計な辺を見ないため)
	REP(i,V)REP(j,i){
		if(cap[i][j] + cap[j][i] > 0){
			network[i].push_back(Edge(i,j,0));
			network[j].push_back(Edge(j,i,0));
		}
	}
	Weight res = 0,f;
	while((f = dfs(network, s, t, INF, cap, flow, visit)) > 0){
		res+=f;
		visit = vector<bool>(V);
	}
	return res;
}








int n, m, l;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	vi d(m);
	REP(i, m) cin >> d[i];
	cin >> l;
	vi e(l);
	REP(i, l) cin >> e[i];
	Graph g(m+l+2);
	int s = m+l;
	int t = s+1;
	REP(i, m) add_edge(g, s, i, d[i]);
	REP(i, l) add_edge(g, m+i, t, e[i]);
	
	REP(i, l){
		int q;
		cin >> q;
		set<int> se;
		REP(j, q){
			int x;
			cin >> x;
			se.insert(x-1);
		}
		REP(j, m)if(!se.count(j)){
			add_edge(g, j, m+i, INF);
		}
	}
//	cout << (maximum_flow(g, s, t)) << endl;
	cout << (maximum_flow(g, s, t) >= n ? "SHIROBAKO" : "BANSAKUTSUKITA") << endl;
	return 0;
}
0