結果

問題 No.421 しろくろチョコレート
ユーザー RubikunRubikun
提出日時 2019-08-04 18:25:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,918 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 172,124 KB
実行使用メモリ 6,180 KB
最終ジャッジ日時 2023-09-22 22:18:43
合計ジャッジ時間 5,179 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 4 ms
5,944 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 4 ms
5,916 KB
testcase_13 WA -
testcase_14 AC 3 ms
5,736 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 3 ms
5,720 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 4 ms
5,736 KB
testcase_25 AC 3 ms
5,756 KB
testcase_26 AC 4 ms
5,764 KB
testcase_27 AC 4 ms
5,848 KB
testcase_28 AC 6 ms
5,884 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 13 ms
6,124 KB
testcase_32 AC 7 ms
5,992 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 9 ms
5,960 KB
testcase_41 AC 5 ms
5,788 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 12 ms
5,996 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 11 ms
6,064 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 13 ms
6,052 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 AC 4 ms
5,952 KB
testcase_64 AC 3 ms
5,720 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<<endl;
    
}
0