結果

問題 No.190 Dry Wet Moist
ユーザー te-sh
提出日時 2016-09-15 11:52:56
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 1,479 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 121,276 KB
実行使用メモリ 13,428 KB
最終ジャッジ日時 2024-06-12 04:23:34
合計ジャッジ時間 3,231 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14 WA * 14
権限があれば一括ダウンロードができます

ソースコード

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