結果

問題 No.459 C-VS for yukicoder
ユーザー miscalcmiscalc
提出日時 2023-05-04 02:49:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 5,442 bytes
コンパイル時間 5,304 ms
コンパイル使用メモリ 282,696 KB
実行使用メモリ 30,904 KB
最終ジャッジ日時 2024-05-01 18:23:28
合計ジャッジ時間 8,909 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 96 ms
30,904 KB
testcase_22 AC 56 ms
26,960 KB
testcase_23 AC 64 ms
27,968 KB
testcase_24 AC 33 ms
15,948 KB
testcase_25 AC 16 ms
9,692 KB
testcase_26 AC 10 ms
6,512 KB
testcase_27 AC 9 ms
6,068 KB
testcase_28 AC 16 ms
9,664 KB
testcase_29 AC 20 ms
11,740 KB
testcase_30 AC 10 ms
6,504 KB
testcase_31 AC 16 ms
9,088 KB
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 20 ms
9,980 KB
testcase_34 AC 22 ms
11,080 KB
testcase_35 AC 5 ms
5,376 KB
testcase_36 AC 17 ms
9,392 KB
testcase_37 AC 5 ms
5,376 KB
testcase_38 AC 20 ms
10,076 KB
testcase_39 AC 5 ms
5,376 KB
testcase_40 AC 15 ms
8,660 KB
testcase_41 AC 4 ms
5,376 KB
testcase_42 AC 13 ms
7,148 KB
testcase_43 AC 20 ms
9,740 KB
testcase_44 AC 7 ms
5,376 KB
testcase_45 AC 6 ms
5,376 KB
testcase_46 AC 5 ms
5,376 KB
testcase_47 AC 4 ms
5,376 KB
testcase_48 AC 19 ms
9,620 KB
testcase_49 AC 5 ms
5,376 KB
testcase_50 AC 19 ms
9,656 KB
testcase_51 AC 4 ms
5,376 KB
testcase_52 AC 9 ms
6,344 KB
testcase_53 AC 5 ms
5,376 KB
testcase_54 AC 21 ms
10,076 KB
testcase_55 AC 6 ms
5,376 KB
testcase_56 AC 13 ms
7,592 KB
testcase_57 AC 5 ms
5,376 KB
testcase_58 AC 22 ms
10,192 KB
testcase_59 AC 6 ms
5,376 KB
testcase_60 AC 10 ms
6,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll safemod(ll A, ll M) {ll res = A % M; if (res < 0) res += M; return res;}
ll divfloor(ll A, ll B) {if (B < 0) A = -A, B = -B; return (A - safemod(A, B)) / B;}
ll divceil(ll A, ll B) {if (B < 0) A = -A, B = -B; return divfloor(A + B - 1, B);}
ll pow_ll(ll A, ll B) {if (A == 0 || A == 1) {return A;} if (A == -1) {return B & 1 ? -1 : 1;} ll res = 1; for (int i = 0; i < B; i++) {res *= A;} return res;}
ll mul_limited(ll A, ll B, ll M = INF) { return A > M / B ? M : A * B; }
ll pow_limited(ll A, ll B, ll M = INF) { if (A == 0 || A == 1) {return A;} ll res = 1; for (int i = 0; i < B; i++) {if (res > M / A) return M; res *= A;} return res;}
ll logfloor(ll A, ll B) {assert(A >= 2); ll res = 0; for (ll tmp = 1; tmp <= B / A; tmp *= A) {res++;} return res;}
ll logceil(ll A, ll B) {assert(A >= 2); ll res = 0; for (ll tmp = 1; tmp < B; tmp *= A) {res++;} return res;}
ll arisum_ll(ll a, ll d, ll n) { return n * a + (n & 1 ? ((n - 1) >> 1) * n : (n >> 1) * (n - 1)) * d; }
ll arisum2_ll(ll a, ll l, ll n) { return n & 1 ? ((a + l) >> 1) * n : (n >> 1) * (a + l); }
ll arisum3_ll(ll a, ll l, ll d) { assert((l - a) % d == 0); return arisum2_ll(a, l, (l - a) / d + 1); }
template<class T> void unique(vector<T> &V) {V.erase(unique(V.begin(), V.end()), V.end());}
template<class T> void sortunique(vector<T> &V) {sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end());}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)
template<class T> void printvec(const vector<T> &V) {int _n = V.size(); for (int i = 0; i < _n; i++) cout << V[i] << (i == _n - 1 ? "" : " ");cout << '\n';}
template<class T> void printvect(const vector<T> &V) {for (auto v : V) cout << v << '\n';}
template<class T> void printvec2(const vector<vector<T>> &V) {for (auto &v : V) printvec(v);}
//*
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
//using mint = modint1000000007;
//using mint = modint;
//*/

// https://atcoder.jp/contests/abc285/editorial/5500
template<class Cap>
struct MaxFlowLowerLimit
{
public:
  struct edge
  {
    int from, to;
    Cap cap_l, cap_r, flow;
    edge(int from, int to, Cap cap_l, Cap cap_r, Cap flow) : from(from), to(to), cap_l(cap_l), cap_r(cap_r), flow(flow) {}
    edge() {}
  };

private:
  int N;
  vector<edge> internal_edges;
  vector<int> idxs;

public:
  mf_graph<Cap> G;
  MaxFlowLowerLimit(int n)
  {
    N = n;
    G = mf_graph<Cap>(N + 2);
  }
  void add_edge(int from, int to, Cap cap_l, Cap cap_r)
  {
    assert(from < N && to < N);
    int idx = G.add_edge(from, to, cap_r - cap_l);
    if (cap_l != 0)
    {
      G.add_edge(N, to, cap_l);
      G.add_edge(from, N + 1, cap_l);
    }
    internal_edges.emplace_back(edge(from, to, cap_l, cap_r, 0));
    idxs.emplace_back(idx);
  }
  Cap flow(int s, int t) // 存在しなければ -1
  {
    assert(s < N && t < N && s != t);
    G.flow(N, N + 1);
    G.flow(s, N + 1);
    G.flow(N, t);
    G.flow(s, t);

    auto es = G.edges();
    Cap res = 0;
    for (auto e : es)
    {
      if (e.to == N + 1 && e.flow != e.cap)
        return -1;
      if (e.from == N && e.flow != e.cap)
        return -1;
      if (e.to == t)
        res += e.flow;
    }
    return res;
  }
  bool flow_exists(int s, int t)
  {
    assert(s < N && t < N && s != t);
    G.add_edge(t, s, numeric_limits<Cap>::max());
    G.flow(N, N + 1);

    auto es = G.edges();
    for (auto e : es)
    {
      if (e.to == N + 1 && e.flow != e.cap)
        return false;
      if (e.from == N && e.flow != e.cap)
        return false;
    }
    return true;
  }
  edge get_edge(int i)
  {
    assert(0 <= i && i < (int)internal_edges.size());
    edge e = internal_edges[i];
    e.flow = e.cap_l + G.get_edge(idxs[i]).flow;
    return e;
  }
  vector<edge> edges()
  {
    vector<edge> res(internal_edges.size());
    for (int i = 0; i < (int)internal_edges.size(); i++)
      res[i] = get_edge(i);
    return res;
  }
};

int main()
{
  ll H, W, N;
  cin >> H >> W >> N;
  vector<string> S(H);
  for (ll i = 0; i < H; i++)
  {
    cin >> S.at(i);
  }
  vector<ll> C(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> C.at(i);
  }

  vector<ll> A(W, 0);
  for (ll i = 0; i < H; i++)
  {
    for (ll j = 0; j < W; j++)
    {
      if (S.at(i).at(j) == '#')
        A.at(j)++;
    }
  }

  MaxFlowLowerLimit<ll> G(1 + N + W + 1);
  for (ll i = 0; i < N; i++)
  {
    G.add_edge(0, 1 + i, 1, 9);
    for (ll j = 0; j < 3; j++)
    {
      G.add_edge(1 + i, 1 + N + C.at(i) + j, 0, 3);
    }
  }
  for (ll i = 0; i < W; i++)
  {
    G.add_edge(1 + N + i, 1 + N + W, A.at(i), A.at(i));
  }
  G.flow(0, 1 + N + W);

  vector res(N, vector(3, 0LL));
  auto es = G.edges();
  for (auto e : es)
  {
    ll i = e.from - 1, j = e.to - 1 - N;
    if (!(0 <= i && i < N) || !(0 <= j && j < W))
      continue;
    res.at(i).at(j - C.at(i)) = e.flow;
  }

  for (ll i = 0; i < N; i++)
  {
    vector<string> ans(3, string(3, '.'));
    for (ll j = 0; j < 3; j++)
    {
      for (ll k = 0; k < res.at(i).at(j); k++)
      {
        ans.at(k).at(j) = '#';
      }
    }
    printvect(ans);
  }
}
0