結果

問題 No.2238 Rock and Hole
ユーザー KudeKude
提出日時 2023-03-03 22:28:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,096 ms / 3,000 ms
コード長 1,814 bytes
コンパイル時間 3,826 ms
コンパイル使用メモリ 237,824 KB
実行使用メモリ 37,632 KB
最終ジャッジ日時 2023-10-18 02:37:47
合計ジャッジ時間 5,518 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 29 ms
13,980 KB
testcase_11 AC 63 ms
26,900 KB
testcase_12 AC 42 ms
21,636 KB
testcase_13 AC 42 ms
21,132 KB
testcase_14 AC 21 ms
12,336 KB
testcase_15 AC 9 ms
6,736 KB
testcase_16 AC 74 ms
37,632 KB
testcase_17 AC 68 ms
32,312 KB
testcase_18 AC 46 ms
27,016 KB
testcase_19 AC 1,096 ms
24,648 KB
testcase_20 AC 83 ms
24,472 KB
testcase_21 AC 138 ms
25,724 KB
testcase_22 AC 66 ms
23,460 KB
testcase_23 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  VI v0, v1;
  rep(i, h) {
    cin >> s[i];
    rep(j, w) {
      if (s[i][j] == 'r') v0.emplace_back(i * w + j);
      else if (s[i][j] == 'h') v1.emplace_back(i * w + j);
    }
  }
  const int hw = h * w, b0 = hw + hw, b1 = b0 + v0.size(), src = b1 + v1.size(), snk = src + 1;
  mf_graph<int> g(snk + 1);
  rep(i, h - 1) rep(j, w) {
    int u = i * w + j, v = u + w;
    if (s[i][j] != 'h') g.add_edge(u, v, 1);
    if (s[i+1][j] != 'h') g.add_edge(v, u, 1);
  }
  rep(i, h) rep(j, w - 1) {
    int u = hw + i * w + j, v = u + 1;
    if (s[i][j] != 'h') g.add_edge(u, v, 1);
    if (s[i][j + 1] != 'h') g.add_edge(v, u, 1);
  }
  rep(i, v0.size()) {
    g.add_edge(src, b0 + i, 1);
    g.add_edge(b0 + i, v0[i], 1);
    g.add_edge(b0 + i, v0[i] + hw, 1);
  }
  rep(j, v1.size()) {
    g.add_edge(b1 + j, snk, 1);
    g.add_edge(v1[j], b1 + j, 1);
    g.add_edge(v1[j] + hw, b1 + j, 1);
  }
  int f = g.flow(src, snk);
  cout << (f == v0.size() ? "Yes\n" : "No\n");
}
0