結果

問題 No.421 しろくろチョコレート
ユーザー femtofemto
提出日時 2016-09-09 23:00:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 415 ms / 2,000 ms
コード長 1,490 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 78,604 KB
実行使用メモリ 9,796 KB
最終ジャッジ日時 2023-10-24 14:45:41
合計ジャッジ時間 4,555 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 13 ms
8,320 KB
testcase_02 AC 6 ms
7,880 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
7,892 KB
testcase_05 AC 3 ms
6,188 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 9 ms
6,252 KB
testcase_08 AC 6 ms
7,948 KB
testcase_09 AC 2 ms
6,228 KB
testcase_10 AC 2 ms
6,080 KB
testcase_11 AC 10 ms
8,276 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 94 ms
9,240 KB
testcase_17 AC 63 ms
9,452 KB
testcase_18 AC 92 ms
9,440 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 24 ms
8,296 KB
testcase_21 AC 53 ms
8,476 KB
testcase_22 AC 12 ms
8,280 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 21 ms
8,700 KB
testcase_29 AC 26 ms
9,244 KB
testcase_30 AC 25 ms
9,084 KB
testcase_31 AC 260 ms
9,796 KB
testcase_32 AC 33 ms
8,800 KB
testcase_33 AC 32 ms
9,040 KB
testcase_34 AC 7 ms
7,824 KB
testcase_35 AC 8 ms
7,844 KB
testcase_36 AC 6 ms
8,200 KB
testcase_37 AC 120 ms
8,844 KB
testcase_38 AC 245 ms
9,540 KB
testcase_39 AC 5 ms
8,084 KB
testcase_40 AC 53 ms
8,364 KB
testcase_41 AC 7 ms
6,304 KB
testcase_42 AC 4 ms
6,228 KB
testcase_43 AC 6 ms
8,140 KB
testcase_44 AC 109 ms
8,380 KB
testcase_45 AC 4 ms
7,944 KB
testcase_46 AC 3 ms
6,052 KB
testcase_47 AC 9 ms
8,208 KB
testcase_48 AC 214 ms
8,460 KB
testcase_49 AC 6 ms
7,988 KB
testcase_50 AC 4 ms
7,960 KB
testcase_51 AC 124 ms
8,348 KB
testcase_52 AC 7 ms
8,264 KB
testcase_53 AC 3 ms
5,868 KB
testcase_54 AC 6 ms
8,052 KB
testcase_55 AC 3 ms
6,124 KB
testcase_56 AC 3 ms
6,128 KB
testcase_57 AC 3 ms
6,076 KB
testcase_58 AC 11 ms
8,204 KB
testcase_59 AC 5 ms
6,196 KB
testcase_60 AC 331 ms
9,612 KB
testcase_61 AC 415 ms
9,604 KB
testcase_62 AC 2 ms
4,348 KB
testcase_63 AC 2 ms
4,348 KB
testcase_64 AC 7 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

const int MAX_V = 2500;

int V;
bool G[MAX_V][MAX_V];
int match[MAX_V];
bool used[MAX_V];

bool dfs(int v) {
	used[v] = true;
	for(int i = 0; i < V; i++) {
		if(!G[v][i]) continue;
		int u = i, w = match[u];
		if(w < 0 || (!used[w] && dfs(w))) {
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int bipartite_matching() {
	int res = 0;
	memset(match, -1, sizeof(match));
	for(int v = 0; v < V; v++) {
		if(match[v] < 0) {
			memset(used, 0, sizeof(used));
			if(dfs(v)) {
				res++;
			}
		}
	}
	return res;
}

int N, M;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
string c[50];
int toV(int x, int y) {
	return y * M + x;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> M;
	V = N * M;
	for(int i = 0; i < N; i++) {
		cin >> c[i];
	}

	int bc = 0, wc = 0;
	for(int y = 0; y < N; y++) {
		for(int x = 0; x < M; x++) {
			if(c[y][x] == '.') continue;
			if(c[y][x] == 'b') bc++;
			if(c[y][x] == 'w') wc++;
			for(int k = 0; k < 4; k++) {
				int nx = x + dx[k], ny = y + dy[k];
				if(0 <= nx && nx < M && 0 <= ny && ny < N && c[ny][nx] != '.') {
					G[toV(x, y)][toV(nx, ny)] = G[toV(nx, ny)][toV(x, y)] = true;
				}
			}
		}
	}
	int m = bipartite_matching();
	bc -= m, wc -= m;
	int ans = m * 100 + min(bc, wc) * 10 + (max(bc, wc) - min(bc, wc));

	cout << ans << endl;
}
0