結果

問題 No.177 制作進行の宮森あおいです!
ユーザー ngtkana
提出日時 2019-08-27 23:27:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,954 bytes
コンパイル時間 2,292 ms
コンパイル使用メモリ 210,936 KB
最終ジャッジ日時 2025-01-07 15:23:44
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
std::cerr << " " << head;
debug_impl(tail...);
}
#define debug(...) std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
debug_impl(__VA_ARGS__);\
std::cerr << std::noboolalpha;
template <typename Value>
struct dinic_edge
{
int to; Value cap; int rev;
dinic_edge(int to, Value cap, int rev): to(to), cap(cap), rev(rev){}
};
template <typename Value>
std::ostream& operator<< (std::ostream& os, const dinic_edge<Value>& e)
{
return os
<< "dinic_edge{"
<< "to:" << e.to << ","
<< "cap:" << e.cap << ","
<< "rev:" << e.rev
<< "}";
}
template <typename Value>
class dinic {
const int n, source, sink;
std::vector<bool> ckd;
std::vector<int> level;
std::vector<std::vector<dinic_edge<Value>>> graph;
static constexpr Value inf = std::numeric_limits<Value>::max();
void bfs ()
{
std::queue<int> que;
que.emplace(source); level.at(source) = 0;
while (!que.empty())
{
auto crr = que.front(); que.pop();
for (auto const& e : graph.at(crr))
{
if (e.cap == 0) continue;
int nxt = e.to;
if (level.at(nxt) != -1) continue;
que.push(nxt);
level.at(nxt) = level.at(crr) + 1;
}
}
}
auto dfs (int crr, int f = inf) -> Value
{
if (crr == sink) return f;
ckd.at(crr) = true;
for (auto& e : graph.at(crr))
{
auto nxt = e.to;
if (ckd.at(nxt) || e.cap == 0 || level.at(crr) >= level.at(nxt)) continue;
auto d = dfs(nxt, std::min(f, e.cap));
if (d > 0)
{
e.cap -= d;
graph.at(nxt).at(e.rev).cap += d;
return d;
}
}
level.at(crr) = -1;
return 0;
}
public:
dinic (int n, int source, int sink) :
n(n), source(source), sink(sink), graph(n)
{}
void insert(int u, int v, Value c)
{
int k = graph.at(u).size();
int l = graph.at(v).size();
graph.at(u).emplace_back(v, c, l);
graph.at(v).emplace_back(u, 0, k);
}
Value build()
{
Value ret = 0;
while (true)
{
level.assign(n, -1);
bfs();
if (level.at(sink) == -1) return ret;
ckd.assign(n, false);
while (true)
{
Value f = dfs(source);
if (f == 0) break;
ret += f;
}
}
}
};
template <typename T>
std::istream& operator>> (std::istream& is, std::vector<T>& v)
{
for (auto & x : v) is >> x;
return is;
}
template <typename T>
std::ostream& operator<< (std::ostream& os, const std::vector<T>& v)
{
auto n = v.size();
os << "{";
for (size_t i = 0; i < n; i++)
os << (i > 0 ? "," : "") << v[i];
return os << "}";
}
int main()
{
std::cin.tie(0); std::cin.sync_with_stdio(false);
int w, n; std::cin >> w >> n;
std::vector<int> a(n); std::cin >> a;
int m; std::cin >> m;
std::vector<int> b(m); std::cin >> b;
auto dnc = dinic<int>(n + m + 2, n + m, n + m + 1);
constexpr int inf = 1 << 30;
rep(i, 0, n) dnc.insert(n + m, i, a.at(i));
rep(j, 0, m) dnc.insert(n + j, n + m + 1, b.at(j));
rep(j, 0, m)
{
std::vector<int> ckd(n, false);
int q; std::cin >> q;
loop(q)
{
int i; std::cin >> i;
i--;
ckd.at(i) = true;
}
rep(i, 0, n) {
if (!ckd.at(i)) {
dnc.insert(i, n + j, inf);
}
}
}
auto ret = dnc.build() >= w;
std::cout << (ret ? "SHIROBAKO" : "BANSAKUTSUKITA") << std::endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0