結果

問題 No.421 しろくろチョコレート
ユーザー a_kawashiroa_kawashiro
提出日時 2017-07-10 13:13:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 2,494 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 86,040 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 14:54:22
合計ジャッジ時間 2,417 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 4 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 9 ms
4,348 KB
testcase_18 AC 11 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 5 ms
4,348 KB
testcase_21 AC 5 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 5 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 4 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 12 ms
4,348 KB
testcase_38 AC 11 ms
4,348 KB
testcase_39 AC 3 ms
4,348 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 AC 3 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 3 ms
4,348 KB
testcase_44 AC 4 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 3 ms
4,348 KB
testcase_47 AC 5 ms
4,348 KB
testcase_48 AC 4 ms
4,348 KB
testcase_49 AC 3 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 6 ms
4,348 KB
testcase_52 AC 3 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 3 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 4 ms
4,348 KB
testcase_59 AC 2 ms
4,348 KB
testcase_60 AC 11 ms
4,348 KB
testcase_61 AC 5 ms
4,348 KB
testcase_62 AC 2 ms
4,348 KB
testcase_63 AC 1 ms
4,348 KB
testcase_64 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

#define MAX_V 5000

struct Edge{ int to,cap,rev; };
int used[MAX_V];
vector<Edge> G[MAX_V];

void addEdge(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<(int)G[v].size();i++){
        Edge &e=G[v][i];
        if(!used[e.to] && 0<e.cap){
            int d=DFS(e.to,t,min(f,e.cap));
            if(0<d){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
int maxFlow(int s,int t){
    int flow=0;
    while(1){
        for(int i=0;i<MAX_V;i++)
            used[i]=false;
        int f=DFS(s,t,INT_MAX);
        if(f==0)
            break;
        flow+=f;
    }
    return flow;
}

int main(void){
    int N,M;
    cin>>N>>M;
    vector<string> vs(N);
    REP(i,N)
        cin>>vs[i];
    int src=N*M,dst=N*M+1,nw=0,nb=0;
    int d[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
    REP(i,N)
        REP(j,M)
            if((i+j)%2==0&&vs[i][j]=='w'){
                nw++;
                addEdge(src,i*M+j,1);
                REP(k,4){
                    int ii=i+d[k][0],jj=j+d[k][1];
                    if(0<=ii&&ii<N&&0<=jj&&jj<M)
                        addEdge(i*M+j,ii*M+jj,1);
                }
            }else if((i+j)%2==1&&vs[i][j]=='b'){
                nb++;
                addEdge(i*M+j,dst,1);
            }
    int f=maxFlow(src,dst);
    int c=min(nw-f,nb-f);
    cout<<f*100+c*10+max(nw-f-c,nb-f-c)<<endl;
     return 0;
}
0