結果

問題 No.421 しろくろチョコレート
ユーザー rsk0315rsk0315
提出日時 2019-02-13 00:25:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,350 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 69,108 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-11 11:04:49
合計ジャッジ時間 4,115 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <string>
#include <utility>
#include <tuple>

constexpr size_t di[] = {size_t(-1), 0, 1, 0};
constexpr size_t dj[] = {0, size_t(-1), 0, 1};

std::pair<int, int> dfs(std::vector<std::string>& s, size_t i, size_t j) {
  std::pair<int, int> wb;
  if (s[i][j] == '.') return {0, 0};
  if (s[i][j] == 'w') ++wb.first;
  if (s[i][j] == 'b') ++wb.second;

  s[i][j] = '.';
  for (int k = 0; k < 4; ++k) {
    size_t ni = i + di[k];
    size_t nj = j + dj[k];
    if (!(ni < s.size() && nj < s[0].length())) continue;
    if (s[ni][nj] == '.') continue;
    auto tmp = dfs(s, ni, nj);
    wb.first += tmp.first;
    wb.second += tmp.second;
  }
  return wb;
}

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  std::vector<std::string> S(N);
  for (auto& si: S) {
    char buf[64];
    scanf("%s", buf);
    si = buf;
  }

  std::vector<std::pair<int, int>> wb;
  for (size_t i = 0; i < N; ++i)
    for (size_t j = 0; j < M; ++j)
      if (S[i][j] != '.') wb.push_back(dfs(S, i, j));

  int res = 0;
  int w = 0;
  int b = 0;
  for (const auto& p: wb) {
    int wi, bi;
    std::tie(wi, bi) = p;
    if (wi < bi) {
      res += 100 * wi;
      b += bi-wi;
    } else {
      res += 100 * bi;
      w += wi-bi;
    }
  }
  if (w > b) std::swap(w, b);
  res += 10*w;
  res += b-w;
  printf("%d\n", res);
}
0