結果

問題 No.421 しろくろチョコレート
ユーザー RubikunRubikun
提出日時 2019-08-04 18:27:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,940 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 174,436 KB
実行使用メモリ 6,540 KB
最終ジャッジ日時 2023-10-24 14:57:59
合計ジャッジ時間 3,526 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,128 KB
testcase_01 AC 7 ms
6,264 KB
testcase_02 AC 5 ms
6,168 KB
testcase_03 AC 4 ms
6,144 KB
testcase_04 AC 4 ms
6,156 KB
testcase_05 AC 5 ms
6,168 KB
testcase_06 AC 4 ms
6,148 KB
testcase_07 AC 6 ms
6,212 KB
testcase_08 AC 5 ms
6,164 KB
testcase_09 AC 4 ms
6,156 KB
testcase_10 AC 4 ms
6,152 KB
testcase_11 AC 7 ms
6,216 KB
testcase_12 AC 4 ms
6,124 KB
testcase_13 AC 4 ms
6,124 KB
testcase_14 AC 3 ms
6,124 KB
testcase_15 AC 4 ms
6,120 KB
testcase_16 AC 9 ms
6,312 KB
testcase_17 AC 12 ms
6,312 KB
testcase_18 AC 14 ms
6,312 KB
testcase_19 AC 4 ms
6,120 KB
testcase_20 AC 8 ms
6,292 KB
testcase_21 AC 9 ms
6,316 KB
testcase_22 AC 6 ms
6,220 KB
testcase_23 AC 3 ms
6,124 KB
testcase_24 AC 4 ms
6,120 KB
testcase_25 AC 4 ms
6,124 KB
testcase_26 AC 3 ms
6,124 KB
testcase_27 AC 3 ms
6,124 KB
testcase_28 AC 6 ms
6,272 KB
testcase_29 AC 8 ms
6,296 KB
testcase_30 AC 7 ms
6,276 KB
testcase_31 AC 13 ms
6,540 KB
testcase_32 AC 7 ms
6,280 KB
testcase_33 AC 8 ms
6,280 KB
testcase_34 AC 4 ms
6,148 KB
testcase_35 AC 4 ms
6,148 KB
testcase_36 AC 6 ms
6,208 KB
testcase_37 AC 15 ms
6,320 KB
testcase_38 AC 16 ms
6,356 KB
testcase_39 AC 6 ms
6,188 KB
testcase_40 AC 10 ms
6,312 KB
testcase_41 AC 5 ms
6,176 KB
testcase_42 AC 4 ms
6,164 KB
testcase_43 AC 5 ms
6,196 KB
testcase_44 AC 12 ms
6,348 KB
testcase_45 AC 4 ms
6,160 KB
testcase_46 AC 4 ms
6,164 KB
testcase_47 AC 7 ms
6,244 KB
testcase_48 AC 10 ms
6,448 KB
testcase_49 AC 5 ms
6,180 KB
testcase_50 AC 4 ms
6,172 KB
testcase_51 AC 13 ms
6,328 KB
testcase_52 AC 6 ms
6,208 KB
testcase_53 AC 5 ms
6,152 KB
testcase_54 AC 5 ms
6,172 KB
testcase_55 AC 4 ms
6,156 KB
testcase_56 AC 4 ms
6,152 KB
testcase_57 AC 4 ms
6,164 KB
testcase_58 AC 8 ms
6,260 KB
testcase_59 AC 5 ms
6,176 KB
testcase_60 AC 17 ms
6,404 KB
testcase_61 AC 12 ms
6,412 KB
testcase_62 AC 3 ms
6,128 KB
testcase_63 AC 3 ms
6,124 KB
testcase_64 AC 3 ms
6,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

vector<int> dx={-1,0,0,1},dy={0,1,-1,0};

struct edge{
    int to,cap,rev;
};
vector<edge> G[MAX];
bool used[MAX];

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

int DFS(int v,int t,int f){
    if(v==t) return f;
    used[v]=true;
    for(int i=0;i<G[v].size();i++){
        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 main(){

    int N,M;cin>>N>>M;
    int wcnt=0,bcnt=0;
    vector<string> S(N);
    for(int i=0;i<N;i++){
        string s;cin>>s;
        for(int j=0;j<M;j++){
            if(s[j]=='w'){
                wcnt++;
                add_edge(99999,i*M+j,1);
            }else if(s[j]=='b'){
                bcnt++;
                add_edge(i*M+j,100000,1);
            }
        }
        S[i]=s;
    }
    
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            for(int k=0;k<4;k++){
                if(i+dx[k]<0) continue;
                if(i+dx[k]>=N) continue;
                if(j+dy[k]<0) continue;
                if(j+dy[k]>=M) continue;
                if(S[i][j]=='w'&&S[i+dx[k]][j+dy[k]]=='b'){
                    add_edge(i*M+j,(i+dx[k])*M+j+dy[k],1);
                }
            }
        }
    }
    
    int sum=max_flow(99999,100000);
    
    cout<<sum*100+(min(wcnt,bcnt)-sum)*10+max(wcnt,bcnt)-sum-(min(wcnt,bcnt)-sum)<<endl;
    
}
0