結果
| 問題 |
No.177 制作進行の宮森あおいです!
|
| コンテスト | |
| ユーザー |
zerokugi
|
| 提出日時 | 2015-04-02 23:45:01 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 2,000 ms |
| コード長 | 4,560 bytes |
| コンパイル時間 | 1,168 ms |
| コンパイル使用メモリ | 120,756 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-04 01:28:06 |
| 合計ジャッジ時間 | 1,768 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
ソースコード
#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;
}
zerokugi