結果
問題 | No.2238 Rock and Hole |
ユーザー |
![]() |
提出日時 | 2023-03-03 22:28:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,138 ms / 3,000 ms |
コード長 | 1,814 bytes |
コンパイル時間 | 2,720 ms |
コンパイル使用メモリ | 226,524 KB |
最終ジャッジ日時 | 2025-02-11 03:12:02 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#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");}