結果

問題 No.421 しろくろチョコレート
ユーザー naimonon77naimonon77
提出日時 2016-09-09 23:49:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,939 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 172,576 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 06:01:09
合計ジャッジ時間 3,439 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
bool test = 0;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX (int)1e6 + 5

char field[55][55];
int H, W;

struct Point {
	int x, y, cnt;
};
pair<ll,ll> grid_bfs(int y,int x) {
	int i, j;
	Point s;
	s.cnt = 0;
	//............
	s.y = y;
	s.x = x;
	//..............
	queue<Point> q;
	q.push(s);
	field[s.y][s.x] = '.';
	pair<ll, ll> cnt = {0,0};
	if ((x + y) % 2 == 0) cnt.first++;
	else cnt.second++;

	while (q.size()) {
		auto now = q.front(); q.pop();
		Point next = now;
		rep(i, 4) {
			next.x = now.x + dx[i];
			next.y = now.y + dy[i];
			if (next.x < 0 || W <= next.x) continue;
			if (next.y < 0 || H <= next.y) continue;
			if (field[next.y][next.x] == '.') continue;
			field[next.y][next.x] = '.';
			if ((next.x + next.y) % 2 == 0) cnt.first++;
			else cnt.second++;
			q.push(next);
		}
	}
	return cnt;
}

signed main(void) {
	ll i, j, k, l;
	cin >> H >> W;
	rep(i, H) rep(j, W) {
		cin >> field[i][j];
	}
	pair<ll, ll> rest = {0,0};
	ll ans = 0;
	rep(i, H) rep(j, W) {
		if (field[i][j] != '.') {
			pair<ll,ll> a = grid_bfs(i, j);
			dump(a.first);
			dump(a.second);
			ans += min(a.first,a.second) * 100;
			if (a.first > a.second) rest.first += a.first - a.second;
			else rest.second += a.second - a.first;
		}
	}
	ans += min(rest.first, rest.second) * 10;
	if (rest.first > rest.second) {
		rest.first -= rest.second;
		rest.second = 0;
	}
	else {
		rest.second -= rest.first;
		rest.second = 0;
	}
	ans += rest.first + rest.second;
	cout << ans << endl;
	return 0;
}
0