結果

問題 No.190 Dry Wet Moist
ユーザー te-shte-sh
提出日時 2016-09-15 12:00:39
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,479 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 110,968 KB
実行使用メモリ 14,048 KB
最終ジャッジ日時 2023-09-02 22:10:00
合計ジャッジ時間 2,467 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,684 KB
testcase_01 AC 3 ms
5,652 KB
testcase_02 AC 3 ms
5,696 KB
testcase_03 AC 4 ms
6,476 KB
testcase_04 AC 4 ms
6,196 KB
testcase_05 AC 4 ms
5,696 KB
testcase_06 AC 4 ms
5,656 KB
testcase_07 AC 3 ms
5,880 KB
testcase_08 AC 4 ms
5,856 KB
testcase_09 AC 4 ms
6,212 KB
testcase_10 AC 3 ms
5,916 KB
testcase_11 AC 3 ms
5,608 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 31 ms
13,540 KB
testcase_23 AC 37 ms
13,428 KB
testcase_24 AC 34 ms
14,048 KB
testcase_25 WA -
testcase_26 AC 4 ms
5,660 KB
testcase_27 AC 27 ms
9,296 KB
testcase_28 AC 14 ms
6,640 KB
testcase_29 AC 17 ms
9,044 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;

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 + 1].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[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