結果

問題 No.190 Dry Wet Moist
ユーザー te-shte-sh
提出日時 2016-09-15 12:04:33
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,693 bytes
コンパイル時間 901 ms
コンパイル使用メモリ 120,960 KB
実行使用メモリ 12,704 KB
最終ジャッジ日時 2024-06-12 04:23:43
合計ジャッジ時間 2,579 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,376 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 23 ms
8,048 KB
testcase_13 AC 28 ms
8,696 KB
testcase_14 AC 22 ms
7,900 KB
testcase_15 AC 30 ms
9,012 KB
testcase_16 AC 36 ms
10,236 KB
testcase_17 AC 7 ms
6,016 KB
testcase_18 AC 20 ms
7,556 KB
testcase_19 AC 36 ms
10,092 KB
testcase_20 AC 26 ms
8,572 KB
testcase_21 AC 6 ms
5,760 KB
testcase_22 AC 33 ms
11,992 KB
testcase_23 AC 39 ms
11,832 KB
testcase_24 AC 36 ms
12,704 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 28 ms
8,556 KB
testcase_28 AC 14 ms
6,216 KB
testcase_29 AC 18 ms
7,196 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) {
    auto a = buf[i + maxA..maxA].sum;
    auto b = buf[maxA];
    auto c = min(a, b);
    r += c;
    if (a - c > 0) r += (a - c) / 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) {
    auto a = buf[maxA + 1..j + 1 + maxA].sum;
    auto b = buf[maxA];
    auto c = min(a, b);
    r += c;
    if (a - c > 0) r += (a - c) / 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