結果

問題 No.421 しろくろチョコレート
ユーザー te-shte-sh
提出日時 2016-09-09 23:53:17
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,616 bytes
コンパイル時間 1,144 ms
コンパイル使用メモリ 112,192 KB
実行使用メモリ 4,888 KB
最終ジャッジ日時 2023-09-02 22:01:59
合計ジャッジ時間 3,878 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

class UnionFind {
  size_t[] par;

  this(size_t n) {
    par = new size_t[](n);
    par[] = size_t.max;
  }

  size_t find(size_t i) {
    if (par[i] == size_t.max) {
      return i;
    } else {
      par[i] = find(par[i]);
      return par[i];
    }
  }

  void unite(size_t i, size_t j) {
    auto pi = find(i), pj = find(j);
    if (pi != pj) par[pj] = pi;
  }
}

void main()
{
  auto rd = readln.split.map!(to!size_t);
  auto n = rd[0], m = rd[1];
  auto sij = iota(n).map!(_ => readln.chomp.map!(c => c != '.').array).array;

  auto uf = new UnionFind(n * m);
  foreach (i; 0..n)
    foreach (j; 0..m) {
      if (sij[i][j]) {
        if (i > 0     && sij[i - 1][j]) uf.unite(i * m + j, (i - 1) * m + j);
        if (i < n - 1 && sij[i + 1][j]) uf.unite(i * m + j, (i + 1) * m + j);
        if (j > 0     && sij[i][j - 1]) uf.unite(i * m + j, i * m + (j - 1));
        if (j < m - 1 && sij[i][j + 1]) uf.unite(i * m + j, i * m + (j + 1));
      }
    }

  auto s = new int[][](n * m, 2);
  foreach (i; 0..n)
    foreach (j; 0..m)
      if (sij[i][j])
        s[uf.find(i * m + j)][(i + j) % 2] += 1;

  auto r = 0;
  foreach (i; 0..n * m) {
    auto a = min(s[i][0], s[i][1]);
    r += a * 100;
    s[i][] -= a;
  }

  auto l1 = 0, l2 = 0;
  foreach (i; 0..n * m) {
    l1 += s[i][0];
    l2 += s[i][1];
  }

  auto b = min(l1, l2);
  r += 10 * b;
  l1 -= b;
  l2 -= b;

  r += l1 + l2;

  writeln(r);
}
0