結果

問題 No.421 しろくろチョコレート
ユーザー Grun1396Grun1396
提出日時 2019-03-11 22:26:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 2,488 bytes
コンパイル時間 652 ms
コンパイル使用メモリ 74,652 KB
実行使用メモリ 28,372 KB
最終ジャッジ日時 2023-10-24 14:57:28
合計ジャッジ時間 3,539 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
28,056 KB
testcase_01 AC 31 ms
28,184 KB
testcase_02 AC 14 ms
28,096 KB
testcase_03 AC 10 ms
28,072 KB
testcase_04 AC 13 ms
28,084 KB
testcase_05 AC 14 ms
28,096 KB
testcase_06 AC 10 ms
28,076 KB
testcase_07 AC 23 ms
28,140 KB
testcase_08 AC 13 ms
28,092 KB
testcase_09 AC 12 ms
28,080 KB
testcase_10 AC 12 ms
28,080 KB
testcase_11 AC 24 ms
28,144 KB
testcase_12 AC 8 ms
28,052 KB
testcase_13 AC 8 ms
28,052 KB
testcase_14 AC 7 ms
28,052 KB
testcase_15 AC 8 ms
28,048 KB
testcase_16 AC 43 ms
28,240 KB
testcase_17 AC 46 ms
28,244 KB
testcase_18 AC 49 ms
28,240 KB
testcase_19 AC 10 ms
28,048 KB
testcase_20 AC 36 ms
28,220 KB
testcase_21 AC 39 ms
28,244 KB
testcase_22 AC 25 ms
28,148 KB
testcase_23 AC 8 ms
28,048 KB
testcase_24 AC 7 ms
28,048 KB
testcase_25 AC 8 ms
28,052 KB
testcase_26 AC 8 ms
28,052 KB
testcase_27 AC 8 ms
28,052 KB
testcase_28 AC 31 ms
28,184 KB
testcase_29 AC 36 ms
28,216 KB
testcase_30 AC 33 ms
28,188 KB
testcase_31 AC 59 ms
28,356 KB
testcase_32 AC 35 ms
28,200 KB
testcase_33 AC 35 ms
28,196 KB
testcase_34 AC 10 ms
28,076 KB
testcase_35 AC 11 ms
28,076 KB
testcase_36 AC 24 ms
28,140 KB
testcase_37 AC 49 ms
28,248 KB
testcase_38 AC 55 ms
28,284 KB
testcase_39 AC 19 ms
28,116 KB
testcase_40 AC 30 ms
28,232 KB
testcase_41 AC 15 ms
28,104 KB
testcase_42 AC 14 ms
28,092 KB
testcase_43 AC 21 ms
28,128 KB
testcase_44 AC 39 ms
28,256 KB
testcase_45 AC 14 ms
28,088 KB
testcase_46 AC 14 ms
28,092 KB
testcase_47 AC 30 ms
28,176 KB
testcase_48 AC 48 ms
28,372 KB
testcase_49 AC 18 ms
28,108 KB
testcase_50 AC 15 ms
28,096 KB
testcase_51 AC 39 ms
28,248 KB
testcase_52 AC 24 ms
28,136 KB
testcase_53 AC 12 ms
28,080 KB
testcase_54 AC 15 ms
28,100 KB
testcase_55 AC 13 ms
28,084 KB
testcase_56 AC 12 ms
28,080 KB
testcase_57 AC 15 ms
28,092 KB
testcase_58 AC 31 ms
28,192 KB
testcase_59 AC 18 ms
28,104 KB
testcase_60 AC 58 ms
28,316 KB
testcase_61 AC 53 ms
28,336 KB
testcase_62 AC 8 ms
28,056 KB
testcase_63 AC 8 ms
28,052 KB
testcase_64 AC 7 ms
28,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
#include <functional>
#include <map>
#include <cstring>
using namespace std;
typedef long long ll;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
const int INF = 1e9;

struct edge {int to,cap,rev;};
const int MAX_V = 1e6;
vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to,int cap){
    G[from].push_back({to,cap,(int)G[to].size()});
    G[to].push_back({from,0,(int)G[from].size()-1});
}

int dfs(int v,int t,int f){
    if(v==t) return f;
    used[v] = true;
    rep(i,G[v].size()){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0){
            int d = dfs(e.to, t, min(f,e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s,int t){
    int flow = 0;
    for(;;){
        memset(used,0,sizeof(used));
        int f = dfs(s,t,INF);
        if(f == 0) return flow;
        flow += f;
    }
}

int V,E;
int f,to,c;
int N,M;
vector<string> vec;

int main(){
    int B=0,W=0;
    cin >> N >> M;
    vec.resize(N);
    rep(i,N) cin >> vec[i];

    rep(i,N){
        rep(j,M){
            if(vec[i][j] == 'w'){
                add_edge(10000,i*M+j ,1);
                W++;
            }else if(vec[i][j]=='b'){
                add_edge(i*M+j,10001,1);
                B++;
            }
        }
    }

    rep(i,N) {
        rep(j,M){
            if(vec[i][j] == 'w'){
                if(i > 0){
                    if(vec[i-1][j] == 'b'){
                        add_edge(i*M+j,(i-1)*M+j ,1);
                    }
                } 
                if(i < N-1){
                    if(vec[i+1][j] == 'b'){
                        add_edge(i*M+j,(i+1)*M+j ,1);
                    }
                }
                if(j > 0){
                    if(vec[i][j-1] == 'b'){
                        add_edge(i*M+j,i*M+j-1,1);
                    }
                }
                if(j < M-1){
                    if(vec[i][j+1] == 'b'){
                        add_edge(i*M+j, i*M+j+1,1);
                    }
                }
            }
        }
    }
    int total_f = max_flow(10000,10001);
    int ans = total_f*100;
    ans += min(B-total_f, W-total_f)*10;
    ans += (max(B-total_f, W-total_f) - min(B-total_f, W-total_f) );
    cout << ans << endl;

    return 0;
}
0