結果
問題 | No.1123 Afforestation |
ユーザー | satashun |
提出日時 | 2020-07-23 13:03:09 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,569 bytes |
コンパイル時間 | 2,744 ms |
コンパイル使用メモリ | 223,268 KB |
実行使用メモリ | 120,032 KB |
最終ジャッジ日時 | 2024-06-23 17:30:57 |
合計ジャッジ時間 | 15,377 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 10 ms
8,576 KB |
testcase_05 | AC | 74 ms
36,736 KB |
testcase_06 | AC | 306 ms
119,736 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 3 ms
5,376 KB |
testcase_11 | AC | 5 ms
5,760 KB |
testcase_12 | AC | 37 ms
21,888 KB |
testcase_13 | AC | 317 ms
120,012 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 3 ms
5,376 KB |
testcase_19 | AC | 10 ms
8,704 KB |
testcase_20 | AC | 83 ms
36,608 KB |
testcase_21 | AC | 300 ms
119,740 KB |
testcase_22 | AC | 351 ms
119,808 KB |
testcase_23 | AC | 347 ms
119,936 KB |
testcase_24 | AC | 336 ms
120,032 KB |
testcase_25 | AC | 323 ms
119,936 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 3 ms
5,376 KB |
testcase_35 | AC | 3 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 2 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 3 ms
5,376 KB |
testcase_40 | AC | 3 ms
5,376 KB |
testcase_41 | AC | 4 ms
5,376 KB |
testcase_42 | AC | 6 ms
5,504 KB |
testcase_43 | AC | 11 ms
8,832 KB |
testcase_44 | AC | 19 ms
11,648 KB |
testcase_45 | AC | 18 ms
11,776 KB |
testcase_46 | AC | 20 ms
12,800 KB |
testcase_47 | AC | 23 ms
12,800 KB |
testcase_48 | AC | 2 ms
5,376 KB |
testcase_49 | AC | 2 ms
5,376 KB |
testcase_50 | AC | 3 ms
5,376 KB |
testcase_51 | AC | 3 ms
5,376 KB |
testcase_52 | AC | 2 ms
5,376 KB |
testcase_53 | AC | 2 ms
5,376 KB |
testcase_54 | AC | 2 ms
5,376 KB |
testcase_55 | AC | 3 ms
5,376 KB |
testcase_56 | AC | 3 ms
5,376 KB |
testcase_57 | AC | 3 ms
5,376 KB |
testcase_58 | AC | 6 ms
5,504 KB |
testcase_59 | AC | 10 ms
8,704 KB |
testcase_60 | AC | 20 ms
11,776 KB |
testcase_61 | AC | 20 ms
11,648 KB |
testcase_62 | AC | 22 ms
12,800 KB |
testcase_63 | AC | 24 ms
12,800 KB |
testcase_64 | AC | 2 ms
5,376 KB |
testcase_65 | AC | 2 ms
5,376 KB |
testcase_66 | AC | 2 ms
5,376 KB |
testcase_67 | AC | 2 ms
5,376 KB |
testcase_68 | AC | 3 ms
5,376 KB |
testcase_69 | AC | 4 ms
5,376 KB |
testcase_70 | AC | 6 ms
5,504 KB |
testcase_71 | AC | 11 ms
8,704 KB |
testcase_72 | AC | 2 ms
5,376 KB |
testcase_73 | WA | - |
testcase_74 | AC | 2 ms
5,376 KB |
testcase_75 | AC | 2 ms
5,376 KB |
testcase_76 | WA | - |
testcase_77 | AC | 2 ms
5,376 KB |
testcase_78 | AC | 2 ms
5,376 KB |
testcase_79 | AC | 2 ms
5,376 KB |
testcase_80 | AC | 1 ms
5,376 KB |
testcase_81 | WA | - |
testcase_82 | AC | 2 ms
5,376 KB |
testcase_83 | AC | 2 ms
5,376 KB |
testcase_84 | AC | 236 ms
119,932 KB |
testcase_85 | AC | 233 ms
119,808 KB |
testcase_86 | AC | 2 ms
5,376 KB |
testcase_87 | AC | 2 ms
5,376 KB |
testcase_88 | AC | 215 ms
104,064 KB |
testcase_89 | AC | 221 ms
104,064 KB |
testcase_90 | AC | 2 ms
5,376 KB |
testcase_91 | AC | 2 ms
5,376 KB |
testcase_92 | AC | 2 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) #define per(i, b) per2(i, 0, b) #define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define ALL(c) (c).begin(), (c).end() constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; } template <class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; } template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "{"; rep(i, v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } #ifdef LOCAL void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif struct FordFulkerson { static constexpr int INF = TEN(9); struct edge { int to, cap, rev; }; int n; VV<edge> g; V<bool> used; FordFulkerson(int n) : n(n), g(n), used(n) {} void add_edge(int from, int to, int cap, int rcap) { g[from].push_back((edge){to, cap, (int)g[to].size()}); g[to].push_back((edge){from, rcap, (int)g[from].size() - 1}); } int dfs(int v, int t, int f) { if (v == t) return f; used[v] = true; for (auto& e : g[v]) { if (!used[e.to] && e.cap > 0) { int d = dfs(e.to, t, min(f, e.cap)); if (d > 0) { e.cap -= d; g[e.to][e.rev].cap += d; return d; } } } return 0; } int max_flow(int s, int t) { int flow = 0; while (1) { fill(used.begin(), used.end(), false); int f = dfs(s, t, INF); if (f == 0) return flow; flow += f; } } }; int state[2010][2010]; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int H, W; cin >> H >> W; V<ll> A(H), B(W), ga, gb; rep(i, H) cin >> A[i]; rep(i, W) cin >> B[i]; ga = A, gb = B; ll s1 = 0, s2 = 0; rep(i, H) s1 += A[i]; rep(i, W) s2 += B[i]; if (s1 != s2) { cout << ":(" << endl; return 0; } { V<int> xid(H); iota(ALL(xid), 0); sort(ALL(xid), [&](int a, int b) { return A[a] > A[b]; }); for (int x : xid) { V<int> yid(W); iota(ALL(yid), 0); sort(ALL(yid), [&](int a, int b) { return B[a] > B[b]; }); int p = 0; while (A[x]) { if (B[yid[p]] == 0) { cout << ":(" << endl; return 0; } state[x][yid[p]] = 1; B[yid[p]]--; p++; A[x]--; } } } V<string> ans(H, string(W, '.')); int K; cin >> K; rep(i, K) { int x, y; cin >> x >> y; --x, --y; if (state[x][y] == 1) { A[x]++; B[y]++; } state[x][y] = -1; ans[x][y] = 'x'; } int node_cnt = H + W + 2; int s = node_cnt - 2, t = node_cnt - 1; FordFulkerson flow(node_cnt); rep(i, H) flow.add_edge(s, i, A[i], ga[i] - A[i]); rep(j, W) flow.add_edge(H + j, t, B[j], gb[j] - B[j]); rep(i, H) { rep(j, W) { if (state[i][j] != -1) { flow.add_edge(i, j + H, 1 - state[i][j], state[i][j]); } } } auto fl = flow.max_flow(s, t); rep(i, H) { for (auto e : flow.g[i]) { if (e.to >= H && e.to < H + W && state[i][e.to - H] != -1 && e.cap == 0) { ans[i][e.to - H] = 'o'; } } } cout << "Yay!" << endl; rep(i, H) cout << ans[i] << '\n'; return 0; }