結果

問題 No.421 しろくろチョコレート
ユーザー ATSATS
提出日時 2016-09-09 23:07:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 2,087 bytes
コンパイル時間 991 ms
コンパイル使用メモリ 96,932 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-24 14:46:04
合計ジャッジ時間 2,443 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cfloat>
#include <climits>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef vector<vector<int> > graph;
struct BGM {
	int L, R; //左右のノード数
	graph g;
	vector<int> r2l; //右->左への対応
	BGM(int L, int R) : L(L), R(R), g(L), r2l(R, -1) {}
	void add_edge(int l, int r) {
		g[l].push_back(r);
	}
	bool augment(int l, vector<bool>& visited) {
		if (l == -1) return true;
		if (visited[l]) return false;
		visited[l] = true;
		vector<int>& e = g[l];
		for (int i = 0; i < e.size(); i++) {
			int r = e[i];
			if (augment(r2l[r], visited)) {
				r2l[r] = l;
				return true;
			}
		}
		return false;
	}
	int match() {
		int cnt = 0;
		for (int l = 0; l < L; l++) {
			vector<bool> visited(L);
			if (augment(l, visited)) ++cnt;
		}
		return cnt;
	}
};

int main() {
	int N,M;
	cin >> N >> M;
	vector<string> S(N);
	int t[50][50];
	int b=0;
	int w=0;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (S[i][j] == 'b') {
				t[i][j] = b;
				b++;
			}else if (S[i][j] == 'w') {
				t[i][j] = w;
				w++;
			}
		}
	}

	BGM bgm(b, w);

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (i < N - 1) {
				if (S[i][j] == 'b'&&S[i + 1][j] == 'w') {
					bgm.add_edge(t[i][j], t[i + 1][j]);
				}

				if (S[i][j] == 'w'&&S[i + 1][j] == 'b') {
					bgm.add_edge(t[i + 1][j], t[i][j]);
				}
			}
			if (j < M - 1) {
				if (S[i][j] == 'b'&&S[i][j + 1] == 'w') {
					bgm.add_edge(t[i][j], t[i][j + 1]);
				}
				if (S[i][j] == 'w'&&S[i][j + 1] == 'b') {
					bgm.add_edge(t[i][j + 1], t[i][j]);
				}
			}
		}
	}
	int a = bgm.match();
	b = b - a;
	w = w - a;
	int v = min(b, w);
	int r = b + w - 2 * v;
	cout << a * 100 + v * 10 + r << endl;
	
	return 0;
}
0