結果

問題 No.2238 Rock and Hole
ユーザー りあんりあん
提出日時 2023-03-03 22:44:31
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 3,000 ms
コード長 2,250 bytes
コンパイル時間 3,999 ms
コンパイル使用メモリ 272,680 KB
実行使用メモリ 16,160 KB
最終ジャッジ日時 2023-10-18 02:55:48
合計ジャッジ時間 5,569 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 1 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 5 ms
5,308 KB
testcase_11 AC 15 ms
10,072 KB
testcase_12 AC 13 ms
9,496 KB
testcase_13 AC 12 ms
9,200 KB
testcase_14 AC 7 ms
6,436 KB
testcase_15 AC 4 ms
4,788 KB
testcase_16 AC 29 ms
15,148 KB
testcase_17 AC 27 ms
16,160 KB
testcase_18 AC 18 ms
11,616 KB
testcase_19 AC 30 ms
10,184 KB
testcase_20 AC 25 ms
10,228 KB
testcase_21 AC 33 ms
10,404 KB
testcase_22 AC 17 ms
8,872 KB
testcase_23 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<atcoder/maxflow>
using namespace std;

using P = pair<int, int>;

const int M = 998244353;
const long long LM = 1LL << 60;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    atcoder::mf_graph<int> mf(h * w + 2);
    int S = h * w, T = h * w + 1;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == 'h') {
                for (int k = i + 1; k < h; ++k) {
                    if (s[k][j] == 'h') {
                        break;
                    }
                    if (s[k][j] == 'r') {
                        mf.add_edge(i * w + j, k * w + j, 1);
                    }
                }
                for (int k = i - 1; k >= 0; --k) {
                    if (s[k][j] == 'h') {
                        break;
                    }
                    if (s[k][j] == 'r') {
                        mf.add_edge(i * w + j, k * w + j, 1);
                    }
                }
                for (int k = j + 1; k < w; ++k) {
                    if (s[i][k] == 'h') {
                        break;
                    }
                    if (s[i][k] == 'r') {
                        mf.add_edge(i * w + j, i * w + k, 1);
                    }
                }
                for (int k = j - 1; k >= 0; --k) {
                    if (s[i][k] == 'h') {
                        break;
                    }
                    if (s[i][k] == 'r') {
                        mf.add_edge(i * w + j, i * w + k, 1);
                    }
                }
            }
        }
    }
    int c = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == 'h') {
                mf.add_edge(S, i * w + j, 1);
            }
            if (s[i][j] == 'r') {
                mf.add_edge(i * w + j, T, 1);
                ++c;
            }
        }
    }
    int cc = mf.flow(S, T);
    if (c == cc) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }

    return 0;
}
0