結果
問題 | No.2238 Rock and Hole |
ユーザー | milanis48663220 |
提出日時 | 2023-03-03 23:03:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 49 ms / 3,000 ms |
コード長 | 3,180 bytes |
コンパイル時間 | 1,617 ms |
コンパイル使用メモリ | 132,592 KB |
実行使用メモリ | 15,960 KB |
最終ジャッジ日時 | 2023-10-18 03:21:06 |
合計ジャッジ時間 | 2,858 ms |
ジャッジサーバーID (参考情報) |
judge15 / 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 | 5 ms
5,292 KB |
testcase_11 | AC | 15 ms
9,524 KB |
testcase_12 | AC | 13 ms
8,952 KB |
testcase_13 | AC | 14 ms
8,656 KB |
testcase_14 | AC | 8 ms
6,156 KB |
testcase_15 | AC | 5 ms
4,660 KB |
testcase_16 | AC | 33 ms
15,172 KB |
testcase_17 | AC | 42 ms
15,960 KB |
testcase_18 | AC | 16 ms
10,772 KB |
testcase_19 | AC | 49 ms
10,308 KB |
testcase_20 | AC | 28 ms
10,560 KB |
testcase_21 | AC | 28 ms
10,528 KB |
testcase_22 | AC | 18 ms
8,904 KB |
testcase_23 | AC | 2 ms
4,348 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <atcoder/maxflow> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int h, w; cin >> h >> w; vector<string> s(h); for(int i = 0; i < h; i++) cin >> s[i]; auto to_idx = [&](int i, int j){ return i*w+j+1; }; atcoder::mf_graph<int> mf(h*w+2); int f = 0, t = h*w+1; int cnt = 0; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ if(s[i][j] == 'h') mf.add_edge(to_idx(i, j), t, 1); if(s[i][j] == 'r') { mf.add_edge(f, to_idx(i, j), 1); cnt++; } } } for(int i = 0; i < h; i++){ vector<int> v; for(int j = 0; j < w; j++){ if(s[i][j] == 'h') v.push_back(j); } for(int j = 0; j < w; j++){ if(s[i][j] == 'r'){ auto p = lower_bound(v.begin(), v.end(), j); if(p != v.end()){ int jj = *p; mf.add_edge(to_idx(i, j), to_idx(i, jj), 1); } if(p != v.begin()){ int jj = *prev(p); mf.add_edge(to_idx(i, j), to_idx(i, jj), 1); } } } } for(int j = 0; j < w; j++){ vector<int> v; for(int i = 0; i < h; i++){ if(s[i][j] == 'h') v.push_back(i); } for(int i = 0; i < h; i++){ if(s[i][j] == 'r') { auto p = lower_bound(v.begin(), v.end(), i); if(p != v.end()){ int ii = *p; mf.add_edge(to_idx(i, j), to_idx(ii, j), 1); } if(p != v.begin()){ int ii = *prev(p); mf.add_edge(to_idx(i, j), to_idx(ii, j), 1); } } } } int flow = mf.flow(f, t); if(flow == cnt){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }