結果

問題 No.421 しろくろチョコレート
ユーザー Grun1396Grun1396
提出日時 2019-03-11 22:21:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,484 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 74,572 KB
実行使用メモリ 28,212 KB
最終ジャッジ日時 2023-09-05 20:16:30
合計ジャッジ時間 8,753 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 RE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 15 ms
27,776 KB
testcase_07 WA -
testcase_08 RE -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 WA -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 WA -
testcase_23 AC 12 ms
27,792 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 12 ms
27,936 KB
testcase_27 RE -
testcase_28 AC 36 ms
28,132 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 WA -
testcase_37 WA -
testcase_38 RE -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 20 ms
27,812 KB
testcase_42 AC 18 ms
27,900 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 RE -
testcase_48 RE -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 43 ms
28,000 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 RE -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 RE -
testcase_59 WA -
testcase_60 RE -
testcase_61 RE -
testcase_62 WA -
testcase_63 RE -
testcase_64 AC 13 ms
27,896 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 < M){
                    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 < N){
                    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