結果
問題 | No.190 Dry Wet Moist |
ユーザー | te-sh |
提出日時 | 2016-09-15 12:04:33 |
言語 | D (dmd 2.105.2) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 1,693 bytes |
コンパイル時間 | 734 ms |
コンパイル使用メモリ | 109,084 KB |
実行使用メモリ | 14,056 KB |
最終ジャッジ日時 | 2023-09-02 22:10:03 |
合計ジャッジ時間 | 2,398 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,676 KB |
testcase_01 | AC | 4 ms
5,676 KB |
testcase_02 | AC | 4 ms
5,644 KB |
testcase_03 | AC | 3 ms
5,624 KB |
testcase_04 | AC | 3 ms
6,008 KB |
testcase_05 | AC | 3 ms
6,180 KB |
testcase_06 | AC | 3 ms
5,664 KB |
testcase_07 | AC | 4 ms
5,944 KB |
testcase_08 | AC | 4 ms
5,932 KB |
testcase_09 | AC | 3 ms
5,924 KB |
testcase_10 | AC | 3 ms
5,920 KB |
testcase_11 | AC | 3 ms
5,660 KB |
testcase_12 | AC | 22 ms
8,812 KB |
testcase_13 | AC | 26 ms
9,276 KB |
testcase_14 | AC | 21 ms
10,236 KB |
testcase_15 | AC | 29 ms
11,080 KB |
testcase_16 | AC | 35 ms
11,368 KB |
testcase_17 | AC | 7 ms
6,404 KB |
testcase_18 | AC | 19 ms
9,116 KB |
testcase_19 | AC | 35 ms
10,576 KB |
testcase_20 | AC | 25 ms
9,072 KB |
testcase_21 | AC | 6 ms
6,344 KB |
testcase_22 | AC | 32 ms
13,556 KB |
testcase_23 | AC | 37 ms
13,416 KB |
testcase_24 | AC | 35 ms
14,056 KB |
testcase_25 | AC | 3 ms
5,636 KB |
testcase_26 | AC | 3 ms
5,988 KB |
testcase_27 | AC | 28 ms
10,300 KB |
testcase_28 | AC | 13 ms
6,856 KB |
testcase_29 | AC | 18 ms
9,020 KB |
ソースコード
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; }