結果
| 問題 |
No.177 制作進行の宮森あおいです!
|
| コンテスト | |
| ユーザー |
tubo28
|
| 提出日時 | 2015-04-03 00:10:36 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 4,533 bytes |
| コンパイル時間 | 1,554 ms |
| コンパイル使用メモリ | 173,180 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-04 01:28:59 |
| 合計ジャッジ時間 | 2,114 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif
typedef ll Weight;
struct Edge {
int src, dst;
Weight weight;
Edge(int src_, int dst_, Weight weight_) :
src(src_), dst(dst_), weight(weight_) { }
};
bool operator < (const Edge &e, const Edge &f) {
return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
ll const inf = 1LL<<60;
struct Dinic {
public:
typedef ll Capacity;
struct Edge;
int n;
vector<vector<Edge> > g;
vector<int> level, iter;
struct Edge {
int dst;
Capacity cap, cap_orig;
int revEdge;
bool isRev;
Edge(int dst_, Capacity cap_, int revEdge_, bool isRev_)
:dst(dst_), cap(cap_), cap_orig(cap_), revEdge(revEdge_), isRev(isRev_) {}
};
Dinic(int n_)
: n(n_), g(vector<vector<Edge> >(n_)), level(n_), iter(n_) {}
void add_edge(int src, int dst, Capacity cap) {
g[src].emplace_back(Edge(dst, cap, g[dst].size(), false));
g[dst].emplace_back(Edge(src, 0, g[src].size() - 1, true));
}
Capacity solve(int src, int dst) {
int flow = 0;
while(1){
bfs(src);
if (level[dst] < 0) return flow;
fill(all(iter), 0);
int f;
while ((f = dfs(src, dst, inf)) > 0) {
flow += f;
}
}
}
private:
void bfs(int s) {
level.assign(n,-1);
queue<int> q; // 辺の数でみた最短距離
level[s] = 0;
q.push(s);
while (q.size()) {
int v = q.front(); q.pop();
rep(i,g[v].size()){
Edge& e = g[v][i];
if (e.cap > 0 && level[e.dst] < 0) {
level[e.dst] = level[v] + 1;
q.push(e.dst);
}
}
}
}
Capacity dfs(int v, int t, Capacity f) {
if (v == t) return f;
for (int &i = iter[v]; i < (int)g[v].size(); i++) {
Edge &e = g[v][i];
if (e.cap > 0 && level[v] < level[e.dst]) {
int d = dfs(e.dst, t, min(f, e.cap));
if (d > 0) {
e.cap -= d;
g[e.dst][e.revEdge].cap += d;
return d;
}
}
}
return 0;
}
};
ll W,N;
ll J[60];
ll M;
ll C[60];
bool ok[60][60];
int main(){
while(cin >> W){
cin >> N;
rep(i,N) cin >> J[i];
cin >> M;
rep(i,M) cin >> C[i];
rep(i,N)rep(j,M) ok[i][j] = true;
rep(i,M){
int Q; cin >> Q;
rep(j,Q){
int X; cin >> X;
X--;
ok[X][i] = false;
}
}
int S = N+M, T = N+M+1;
Dinic g(N+M+2);
rep(i,N){
g.add_edge(S,i,J[i]);
}
rep(i,N)rep(j,M){
if(ok[i][j]){
g.add_edge(i,N+j,min(J[i],C[j]));
}
}
rep(i,M){
g.add_edge(i+N,T,C[i]);
}
ll f = g.solve(S,T);
puts(f >= W ? "SHIROBAKO" : "BANSAKUTSUKITA");
}
}
tubo28