結果
| 問題 |
No.421 しろくろチョコレート
|
| ユーザー |
bal4u
|
| 提出日時 | 2019-08-18 07:41:00 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,956 bytes |
| コンパイル時間 | 387 ms |
| コンパイル使用メモリ | 32,128 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-01 13:34:00 |
| 合計ジャッジ時間 | 2,117 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 64 WA * 1 |
コンパイルメッセージ
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();
| ^~
ソースコード
// 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;
}
bal4u