結果
問題 | No.2238 Rock and Hole |
ユーザー |
![]() |
提出日時 | 2023-03-03 22:01:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 54 ms / 3,000 ms |
コード長 | 1,096 bytes |
コンパイル時間 | 4,309 ms |
コンパイル使用メモリ | 259,200 KB |
最終ジャッジ日時 | 2025-02-11 02:32:22 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ int h,w; cin>>h>>w; vector<string> s(h); rep(i,h)cin>>s[i]; vector<pair<int,int>> rs,hs; rep(i,h){ rep(j,w){ if(s[i][j]=='h')hs.emplace_back(i,j); if(s[i][j]=='r')rs.emplace_back(i,j); } } int x = rs.size(); int y = hs.size(); mf_graph<int> G(x + y + 2); vector<int> dx = {1,-1,0,0},dy = {0,0,1,-1}; int S = x + y; int T = S + 1; rep(i,x){ G.add_edge(S,i,1); rep(j,4){ int xx = rs[i].first,yy = rs[i].second; while(true){ xx += dx[j]; yy += dy[j]; if(xx<0||xx>=h||yy<0||yy>=w)break; if(s[xx][yy]=='h'){ int ii = distance(hs.begin(),lower_bound(hs.begin(),hs.end(),make_pair(xx,yy))); G.add_edge(i,x + ii,1); break; } } } } rep(i,y){ G.add_edge(x + i,T,1); } if(G.flow(S,T)==x)cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }