結果

問題 No.177 制作進行の宮森あおいです!
ユーザー jupiro
提出日時 2020-07-10 21:03:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 3,248 bytes
コンパイル時間 2,725 ms
コンパイル使用メモリ 141,908 KB
最終ジャッジ日時 2025-01-11 17:33:03
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:110:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  110 |         int W; scanf("%d", &W);
      |                ~~~~~^~~~~~~~~~
main.cpp:111:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  111 |         int n; scanf("%d", &n);
      |                ~~~~~^~~~~~~~~~
main.cpp:112:60: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  112 |         vector<int> J(n); for (int i = 0; i < n; i++) scanf("%d", &J[i]);
      |                                                       ~~~~~^~~~~~~~~~~~~
main.cpp:113:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  113 |         int m; scanf("%d", &m);
      |                ~~~~~^~~~~~~~~~
main.cpp:114:60: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  114 |         vector<int> C(m); for (int i = 0; i < m; i++) scanf("%d", &C[i]);
      |                                                       ~~~~~^~~~~~~~~~~~~
main.cpp:117:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  117 |                 int Q; scanf("%d", &Q);
      |                        ~~~~~^~~~~~~~~~
main.cpp:119:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  119 |                         int x; scanf("%d", &x);
      |                                ~~~~~^~~~~~~~~~

ソースコード

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

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
struct Dinic {
struct edge {
int to;
ll cap;
int rev;
bool isrev;
int idx;
edge(int _to, ll _cap, int _rev, bool _isrev, int _idx) :to(_to), cap(_cap), rev(_rev), isrev(_isrev), idx(_idx) {}
};
vector<vector<edge>> g;
vector<int> min_cost, iter;
Dinic(int n) :g(n) {}
void add_edge(int from, int to, ll cap, int idx = -1) {
g[from].emplace_back(to, cap, (int)g[to].size(), false, idx);
g[to].emplace_back(from, 0, (int)g[from].size() - 1, true, idx);
}
bool bfs(int s, int t) {
min_cost.assign(g.size(), -1);
queue<int> q;
q.emplace(s);
min_cost[s] = 0;
while (!q.empty() && min_cost[t] == -1) {
int cur = q.front();
q.pop();
for (auto& e : g[cur]) {
if (e.cap > 0 && min_cost[e.to] == -1) {
min_cost[e.to] = min_cost[cur] + 1;
q.push(e.to);
}
}
}
return min_cost[t] != -1;
}
ll dfs(int idx, const int t, ll flow) {
if (idx == t) return flow;
for (int& i = iter[idx]; i < g[idx].size(); i++) {
edge& e = g[idx][i];
if (e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
ll d = dfs(e.to, t, min(flow, e.cap));
if (d > 0) {
e.cap -= d;
g[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
ll max_flow(int s, int t) {
ll flow = 0;
while (bfs(s, t)) {
iter.assign(g.size(), 0);
ll f = 0;
while ((f = dfs(s, t, INF)) > 0) flow += f;
}
return flow;
}
};
int main()
{
/*
cin.tie(nullptr);
ios::sync_with_stdio(false);
*/
int W; scanf("%d", &W);
int n; scanf("%d", &n);
vector<int> J(n); for (int i = 0; i < n; i++) scanf("%d", &J[i]);
int m; scanf("%d", &m);
vector<int> C(m); for (int i = 0; i < m; i++) scanf("%d", &C[i]);
vector<vector<bool>> bad(n, vector<bool>(m, false));
for (int i = 0; i < m; i++) {
int Q; scanf("%d", &Q);
for (int j = 0; j < Q; j++) {
int x; scanf("%d", &x);
x--;
bad[x][i] = true;
}
}
Dinic g(n + m + 2);
int s = n + m;
int t = n + m + 1;
for (int i = 0; i < n; i++) g.add_edge(s, i, J[i]);
for (int i = 0; i < m; i++) g.add_edge(i + n, t, C[i]);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (bad[i][j]) continue;
g.add_edge(i, j + n, INF);
}
}
ll mx = g.max_flow(s, t);
if (mx >= W) puts("SHIROBAKO");
else puts("BANSAKUTSUKITA");
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0