結果

問題 No.1123 Afforestation
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-07-22 23:55:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,578 bytes
コンパイル時間 1,107 ms
コンパイル使用メモリ 103,532 KB
実行使用メモリ 121,844 KB
最終ジャッジ日時 2023-09-05 05:46:05
合計ジャッジ時間 19,314 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,848 KB
testcase_01 AC 2 ms
7,600 KB
testcase_02 AC 3 ms
7,812 KB
testcase_03 AC 4 ms
7,976 KB
testcase_04 AC 27 ms
8,604 KB
testcase_05 AC 1,455 ms
36,160 KB
testcase_06 AC 752 ms
113,460 KB
testcase_07 AC 2 ms
7,552 KB
testcase_08 AC 2 ms
7,600 KB
testcase_09 AC 2 ms
7,560 KB
testcase_10 AC 3 ms
7,668 KB
testcase_11 AC 10 ms
8,048 KB
testcase_12 AC 578 ms
17,120 KB
testcase_13 AC 733 ms
113,396 KB
testcase_14 AC 3 ms
7,816 KB
testcase_15 AC 2 ms
7,856 KB
testcase_16 AC 2 ms
7,668 KB
testcase_17 AC 2 ms
7,688 KB
testcase_18 AC 4 ms
7,648 KB
testcase_19 AC 30 ms
8,628 KB
testcase_20 TLE -
testcase_21 AC 696 ms
117,112 KB
testcase_22 AC 674 ms
113,120 KB
testcase_23 AC 685 ms
113,588 KB
testcase_24 AC 690 ms
113,384 KB
testcase_25 AC 692 ms
117,132 KB
testcase_26 AC 2 ms
7,656 KB
testcase_27 AC 4 ms
7,656 KB
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


namespace MF {
	const int LIM_N = 10010;
	const int LIM_M = 5000010;
	typedef int wint;
	const wint wEPS = 0;
	const wint wINF = 1001001001;
	int n, m, ptr[LIM_N], nxt[LIM_M * 2], zu[LIM_M * 2];
	wint capa[LIM_M * 2], tof;
	int lev[LIM_N], see[LIM_N], que[LIM_N], *qb, *qe;
	void init(int _n) {
		n = _n; m = 0; fill(ptr, ptr + n, -1);
	}
	void ae(int u, int v, wint w0, wint w1 = 0) {
		nxt[m] = ptr[u]; ptr[u] = m; zu[m] = v; capa[m] = w0; ++m;
		nxt[m] = ptr[v]; ptr[v] = m; zu[m] = u; capa[m] = w1; ++m;
	}
	wint augment(int src, int ink, wint flo) {
		if (src == ink) return flo;
		for (int &i = see[src]; ~i; i = nxt[i]) if (capa[i] > wEPS && lev[src] < lev[zu[i]]) {
			const wint f = augment(zu[i], ink, min(flo, capa[i]));
			if (f > wEPS) {
				capa[i] -= f; capa[i ^ 1] += f; return f;
			}
		}
		return 0;
	}
	bool solve(int src, int ink, wint flo = wINF) {
		for (tof = 0; tof + wEPS < flo; ) {
			qb = qe = que; fill(lev, lev + n, -1);
			for (lev[*qe++ = src] = 0, see[src] = ptr[src]; qb != qe; ) {
				const int u = *qb++;
				for (int i = ptr[u]; ~i; i = nxt[i]) if (capa[i] > wEPS) {
					const int v = zu[i];
					if (lev[v] == -1) {
						lev[*qe++ = v] = lev[u] + 1; see[v] = ptr[v];
						if (v == ink) goto au;
					}
				}
			}
			return false;
		au:	for (wint f; (f = augment(src, ink, flo - tof)) > wEPS; tof += f);
		}
		return true;
	}
}


int H, W;
vector<int> A, B;
int K;
vector<int> X, Y;

int main() {
  for (; ~scanf("%d%d", &H, &W); ) {
    A.resize(H);
    for (int x = 0; x < H; ++x) {
      scanf("%d", &A[x]);
    }
    B.resize(W);
    for (int y = 0; y < W; ++y) {
      scanf("%d", &B[y]);
    }
    scanf("%d", &K);
    X.resize(K);
    Y.resize(K);
    for (int k = 0; k < K; ++k) {
      scanf("%d%d", &X[k], &Y[k]);
      --X[k];
      --Y[k];
    }
    
    vector<vector<int>> ids(H, vector<int>(W, -1));
    for (int k = 0; k < K; ++k) {
      ids[X[k]][Y[k]] = -2;
    }
    MF::init(2 + H + W);
    int ASum = 0, BSum = 0;
    for (int x = 0; x < H; ++x) {
      ASum += A[x];
      MF::ae(0, 2 + x, A[x]);
    }
    for (int y = 0; y < W; ++y) {
      BSum += B[y];
      MF::ae(2 + H + y, 1, B[y]);
    }
    for (int x = 0; x < H; ++x) for (int y = 0; y < W; ++y) {
      if (ids[x][y] == -1) {
        ids[x][y] = MF::m;
        MF::ae(2 + x, 2 + H + y, 1);
      }
    }
    const bool res = MF::solve(0, 1, max(ASum, BSum));
    if (res) {
      puts("Yay!");
      for (int x = 0; x < H; ++x) {
        for (int y = 0; y < W; ++y) {
          putchar((ids[x][y] == -2) ? 'x' : MF::capa[ids[x][y]] ? '.' : 'o');
        }
        puts("");
      }
    } else {
      puts(":(");
    }
  }
  return 0;
}
0