結果

問題 No.421 しろくろチョコレート
ユーザー bal4ubal4u
提出日時 2019-08-18 07:41:00
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,956 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 31,872 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 22:43:23
合計ジャッジ時間 3,278 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 1 ms
6,676 KB
testcase_20 AC 1 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 1 ms
6,676 KB
testcase_24 AC 1 ms
6,676 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 1 ms
6,676 KB
testcase_27 AC 1 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 1 ms
6,676 KB
testcase_30 AC 1 ms
6,676 KB
testcase_31 AC 4 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 1 ms
6,676 KB
testcase_35 AC 1 ms
6,676 KB
testcase_36 AC 1 ms
6,676 KB
testcase_37 AC 1 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 1 ms
6,676 KB
testcase_42 AC 1 ms
6,676 KB
testcase_43 AC 1 ms
6,676 KB
testcase_44 AC 3 ms
6,676 KB
testcase_45 AC 1 ms
6,676 KB
testcase_46 AC 1 ms
6,676 KB
testcase_47 AC 1 ms
6,676 KB
testcase_48 AC 3 ms
6,676 KB
testcase_49 AC 1 ms
6,676 KB
testcase_50 AC 1 ms
6,676 KB
testcase_51 AC 2 ms
6,676 KB
testcase_52 AC 1 ms
6,676 KB
testcase_53 AC 1 ms
6,676 KB
testcase_54 AC 1 ms
6,676 KB
testcase_55 AC 1 ms
6,676 KB
testcase_56 WA -
testcase_57 AC 1 ms
6,676 KB
testcase_58 AC 1 ms
6,676 KB
testcase_59 AC 1 ms
6,676 KB
testcase_60 AC 3 ms
6,676 KB
testcase_61 AC 6 ms
6,676 KB
testcase_62 AC 1 ms
6,676 KB
testcase_63 AC 1 ms
6,676 KB
testcase_64 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:9:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:15:24: note: in expansion of macro 'gc'
   15 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.421 しろくろチョコレート
// bal4u 2019.8.18

#include <stdio.h>
#include <string.h>

//// 入出力関係
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() { // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void ins(char *s) { // 文字列の入力 スペース以下の文字で入力終了
	char *p = s;
	do *s = gc();
	while (*s++ > ' ');
	*--s = 0;
}

//// 二部マッチング
#define MAX 2600
int  V;
int  hi[MAX], to[MAX][8];
char seen[MAX];
int  match[MAX];

int bpm(int u);
int bipartiteMatching(int m)
{
	int u, max;

	memset(match, -1, sizeof(match));
	max = 0;
	for (u = 0; u < m; u++) {
		memset(seen, 0, sizeof(seen));
		if (bpm(u)) max++;
	}
	return max;
}

int bpm(int u)
{
	int i, v;

	for (i = 0; i < hi[u]; i++) {
		v = to[u][i];
		if (seen[v]) continue;
		seen[v] = 1;
		if (match[v] < 0 || bpm(match[v])) {
			match[u] = v, match[v] = u;
			return 1;
		}
	}
	return 0;
}

//// 本問題関連
int H, W;
char map[53][53];
#define MIN(a,b)  ((a)<=(b)?(a):(b))
#define rc2id(r, c)  ((r)*W+(c))
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

int main()
{
	int i, r, c, t, rr, cc, tt, w, b, ans;

	H = in(), W = in();
	w = b = 0; for (r = 0; r < H; r++) {
		ins(map[r]);
		for (c = 0; c < W; c++) {
			if (map[r][c] == 'w') w++;
			else if (map[r][c] == 'b') b++;
		}
	}
	
	if ((w | b) == 0) ans = 0;
	else if ((w & b) == 0) ans = w + b;
	else {
		for (r = 0; r < H; r++) for (c = r&1; c < W; c+=2) if (map[r][c] == 'w') {
			t = rc2id(r, c);
			for (i = 0; i < 4; i++) {
				rr = r+mv[i][0], cc = c+mv[i][1];
				if (rr >= 0 && rr < H && cc >= 0 && cc < W && map[rr][cc] == 'b') {
					tt = rc2id(rr, cc), to[tt][hi[tt]++] = t;
				}
			}
		}
	
		t = bipartiteMatching(H*W);
		w -= t, b -= t, ans = 100 * t;
		t = MIN(w, b), 	ans += 10 * t;
		w -= t, b -= t, ans += w + b;
	}
	printf("%d\n", ans);
	return 0;
}
0