結果

問題 No.421 しろくろチョコレート
ユーザー koprickykopricky
提出日時 2017-07-21 19:18:38
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,947 bytes
コンパイル時間 1,450 ms
コンパイル使用メモリ 172,476 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 10:01:56
合計ジャッジ時間 3,187 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 WA -
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 6 ms
6,940 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 4 ms
6,940 KB
testcase_21 AC 5 ms
6,944 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 WA -
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 3 ms
6,940 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 8 ms
6,944 KB
testcase_32 AC 3 ms
6,944 KB
testcase_33 WA -
testcase_34 AC 2 ms
6,940 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 6 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 3 ms
6,944 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 2 ms
6,944 KB
testcase_44 AC 4 ms
6,940 KB
testcase_45 AC 2 ms
6,940 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 3 ms
6,940 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 2 ms
6,940 KB
testcase_54 AC 2 ms
6,940 KB
testcase_55 AC 1 ms
6,944 KB
testcase_56 AC 1 ms
6,944 KB
testcase_57 WA -
testcase_58 AC 4 ms
6,940 KB
testcase_59 AC 2 ms
6,940 KB
testcase_60 AC 7 ms
6,940 KB
testcase_61 AC 7 ms
6,940 KB
testcase_62 AC 2 ms
6,944 KB
testcase_63 AC 1 ms
6,944 KB
testcase_64 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void add_edge(int, int, int)’:
main.cpp:38:51: warning: narrowing conversion of ‘G[to].std::vector<edge>::size()’ from ‘std::vector<edge>::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing]
   38 |         G[from].push_back((edge){to,cap,G[to].size()});
      |                                         ~~~~~~~~~~^~
main.cpp:39:53: warning: narrowing conversion of ‘(G[from].std::vector<edge>::size() - 1)’ from ‘std::vector<edge>::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing]
   39 |         G[to].push_back((edge){from,0,G[from].size()-1});
      |                                       ~~~~~~~~~~~~~~^~

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 2502;

char c[52][52];
vector<P> od,ev;
vector<int> kind1,kind2;

struct edge
{
	int to,cap,rev;
};

vector<edge> G[MAX_N];
int level[MAX_N];
int iter[MAX_N];

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

void bfs(int s)
{
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while(!que.empty()){
		int v = que.front();
		que.pop();
		rep(i,G[v].size()){
			edge &e = G[v][i];
			if(e.cap > 0 && level[e.to] < 0){
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v,int t,int f)
{
	if(v==t){
		return f;
	}
	for(int &i = iter[v];i<G[v].size();i++){
		edge &e = G[v][i];
		if(e.cap > 0 && level[v] < level[e.to]){
			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(;;){
		bfs(s);
		if(level[t]<0){
			return flow;
		}
		memset(iter,0,sizeof(iter));
		int f;
		while((f=dfs(s,t,INF)) > 0){
			flow += f;
		}
	}
}


int main()
{
    int n,m;
    cin >> n >> m;
    int wnum = 0,bnum = 0;
    rep(i,n){
        rep(j,m){
            cin >> c[i][j];
            if(c[i][j] == 'w'){
                if((i+j)%2){
                    od.pb(P(i,j));
                    kind1.pb(0);
                }else{
                    ev.pb(P(i,j));
                    kind2.pb(0);
                }
                wnum++;
            }else if(c[i][j] == 'b'){
                if((i+j)%2){
                    od.pb(P(i,j));
                    kind1.pb(1);
                }else{
                    ev.pb(P(i,j));
                    kind2.pb(1);
                }
                bnum++;
            }
        }
    }
    int l = (int)od.size();
    int r = (int)ev.size();
    rep(i,l){
        add_edge(0,i+1,1);
    }
    rep(i,l){
        rep(j,r){
            P p1 = od[i];
            P p2 = ev[j];
            if(kind1[i] != kind2[j]){
                if(abs(p1.fi-p2.fi) + abs(p1.se-p2.se) == 1){
                    add_edge(i+1,l+j+1,1);
                }
            }
        }
    }
    rep(i,r){
        add_edge(l+i+1,l+r+1,1);
    }
    int f = max_flow(0,l+r+1);
    cout << max(0,bnum-wnum) + 10 * (min(wnum,bnum) - f) + 100 * f << endl;
    return 0;
}
0