結果
| 問題 |
No.421 しろくろチョコレート
|
| ユーザー |
|
| 提出日時 | 2016-09-09 23:13:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,059 bytes |
| コンパイル時間 | 1,512 ms |
| コンパイル使用メモリ | 168,392 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-16 18:32:31 |
| 合計ジャッジ時間 | 2,936 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 WA * 46 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
int dh[] = {1, -1, 0, 0};
int dw[] = {0, 0, 1, -1};
int n, m;
int dfs(vector<string>& s, int h, int w, int& c) {
int res = 0;
if (s[h][w] == 'w') c++;
else c--;
if (c == 0) res += 100;
s[h][w] = '.';
for (int i = 0; i < 4; i++) {
int h1 = h + dh[i];
int w1 = w + dw[i];
if (h1 < 0 || h1 >= n || w1 < 0 || w1 >= m) continue;
if (s[h1][w1] == '.') continue;
res += dfs(s, h1, w1, c);
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
vector<string> s(n);
for (int i = 0; i < n; i++) cin >> s[i];
int c_all = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int c = 0;
if (s[i][j] != '.') ans += dfs(s, i, j, c);
if (c_all * c < 0) ans += min(abs(c_all), abs(c)) * 10;
c_all += c;
}
}
ans += abs(c_all);
cout << ans << "\n";
return 0;
}