結果

問題 No.190 Dry Wet Moist
ユーザー te-shte-sh
提出日時 2016-09-15 11:52:56
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,479 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 109,016 KB
実行使用メモリ 14,076 KB
最終ジャッジ日時 2023-09-02 22:09:53
合計ジャッジ時間 3,571 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,960 KB
testcase_01 AC 3 ms
5,916 KB
testcase_02 AC 3 ms
5,656 KB
testcase_03 AC 3 ms
5,656 KB
testcase_04 AC 3 ms
6,468 KB
testcase_05 AC 3 ms
5,716 KB
testcase_06 AC 3 ms
5,648 KB
testcase_07 WA -
testcase_08 AC 4 ms
5,900 KB
testcase_09 AC 3 ms
5,720 KB
testcase_10 WA -
testcase_11 AC 3 ms
5,668 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 33 ms
13,568 KB
testcase_23 AC 37 ms
13,440 KB
testcase_24 AC 35 ms
14,076 KB
testcase_25 AC 3 ms
5,668 KB
testcase_26 AC 4 ms
5,920 KB
testcase_27 WA -
testcase_28 AC 14 ms
6,676 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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;

const maxA = 10 ^^ 5;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto ai = readln.split.map!(to!int).array;

  auto buf = new int[](maxA * 2 + 1);
  foreach (a; ai) ++buf[a + maxA];

  auto d = dry(buf.dup);
  auto w = wet(buf.dup);
  auto m = moist(buf.dup);
  writeln(d, " ", w, " ", m);
}

int move(int[] buf, int i, int d)
{
  while (buf[i + maxA] == 0 && i != 0) i += d;
  return i;
}

int dry(int[] buf)
{
  auto i = move(buf, -maxA, 1), j = move(buf, maxA, -1), r = 0;
  while (i != 0 && j != 0) {
    if (-i > j) {
      ++r;
      --buf[i + maxA];
      --buf[j + maxA];
      i = move(buf, i, 1);
      j = move(buf, j, -1);
    } else {
      j = move(buf, j - 1, -1);
    }
  }
  if (j == 0) r += buf[i + maxA..maxA].sum / 2;
  return r;
}

int wet(int[] buf)
{
  auto i = move(buf, -maxA, 1), j = move(buf, maxA, -1), r = 0;
  while (i != 0 && j != 0) {
    if (-i < j) {
      ++r;
      --buf[i + maxA];
      --buf[j + maxA];
      i = move(buf, i, 1);
      j = move(buf, j, -1);
    } else {
      i = move(buf, i + 1, 1);
    }
  }
  if (i == 0) r += buf[1 + maxA..j + 1 + maxA].sum / 2;
  return r;
}

int moist(int[] buf)
{
  auto r = 0;
  r += buf[maxA] / 2;
  foreach (i; 1..maxA+1)
    r += min(buf[-i + maxA], buf[i + maxA]);
  return r;
}
0