結果
問題 |
No.421 しろくろチョコレート
|
ユーザー |
|
提出日時 | 2016-09-09 23:55:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,909 bytes |
コンパイル時間 | 1,800 ms |
コンパイル使用メモリ | 172,252 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-16 18:47:47 |
合計ジャッジ時間 | 2,960 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 WA * 33 |
ソースコード
#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); 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.first = 0; } ans += rest.first + rest.second; cout << ans << endl; return 0; }