結果

問題 No.2412 YOU Grow Bigger!
ユーザー hourenhouren
提出日時 2023-08-11 22:35:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,635 bytes
コンパイル時間 2,280 ms
コンパイル使用メモリ 189,944 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 13:39:35
合計ジャッジ時間 3,266 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 WA -
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/maxflow>
using namespace atcoder;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);

int H[] = {0,1,1,1,0,-1,-1,-1}, W[] = {1,1,0,-1,-1,-1,0,1};
bool f(int p, int q, vector<string>& s){
    for(int i=p-1;i<=p+1;i++)for(int j=q-1;j<=q+1;j++) if(s[i][j]=='#') return false;
    return true;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    mf_graph<int> g((h-2)*(w-2));
    vector<vector<bool>> seen(h,vector<bool>(w,false));
    rep(i,h) seen[i][0] = seen[i][w-1] = true;
    rep(i,w) seen[0][i] = seen[h-1][i] = true;
    queue<pair<int,int>> que;
    que.push({1,1});
    seen[1][1] = true;
    while(que.size()){
        int p,q;
        tie(p,q) = que.front();
        que.pop();
        rep(i,8){
            int np = p+H[i], nq = q+W[i];
            if(seen[np][nq] || !f(np,nq,s)) continue;
            seen[np][nq] = true;
            g.add_edge((p-1)*(w-2)+(q-1), (np-1)*(w-2)+(nq-1),1);
            g.add_edge((np-1)*(w-2)+(nq-1), (p-1)*(w-2)+(q-1),1);
            que.push({np,nq});
        }
    }
    cout << g.flow(0, (h-2)*(w-2)-1) << '\n';
    return 0;
}
0