結果

問題 No.190 Dry Wet Moist
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-11-01 18:04:59
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,442 bytes
コンパイル時間 1,665 ms
コンパイル使用メモリ 165,352 KB
実行使用メモリ 20,044 KB
最終ジャッジ日時 2023-09-02 22:40:46
合計ジャッジ時間 4,137 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 3 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 54 ms
10,732 KB
testcase_13 AC 69 ms
11,376 KB
testcase_14 AC 53 ms
10,484 KB
testcase_15 AC 79 ms
11,956 KB
testcase_16 AC 99 ms
16,836 KB
testcase_17 AC 13 ms
4,680 KB
testcase_18 AC 44 ms
8,564 KB
testcase_19 AC 98 ms
11,888 KB
testcase_20 AC 65 ms
11,204 KB
testcase_21 AC 8 ms
4,368 KB
testcase_22 AC 72 ms
12,564 KB
testcase_23 AC 145 ms
20,044 KB
testcase_24 AC 108 ms
17,248 KB
testcase_25 AC 1 ms
4,372 KB
testcase_26 AC 1 ms
4,368 KB
testcase_27 AC 83 ms
11,480 KB
testcase_28 AC 38 ms
8,080 KB
testcase_29 AC 49 ms
10,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

void main() {
    int N; readf("%d\n", &N);
    auto A = readln.chomp.split(" ").map!(to!int).array;

    int m = 0;
    int z = 0;
    int[int] count;
    foreach (a; A) {
        if (a < 0) count[a] = count.get(a, 0) + 1;
        else if (a == 0) z++;
    }
    foreach (a; A) {
        if (count.get(-a, 0) > 0) {
            count[-a]--;
            m++;
        }
    }
    m += z / 2;

    int calc(int[] W, BinaryHeap!(int[], "a < b") PQ) {
        int ans = 0;
        foreach (i, w; W) {
            if (PQ.empty) {
                break;
            }
            while (! PQ.empty) {
                int c = PQ.front; PQ.removeFront;
                if (c < w) {
                    ans++;
                    break;
                }
            }
        }
        int x = min(W.size - ans, z);
        ans += x + (W.size - ans - x) / 2;
        return ans;
    }

    int w = calc( A.filter!"a > 0".array.sort!"a > b".array, A.filter!"a < 0".map!"-a".array.heapify );
    int d = calc( A.filter!"a < 0".map!"-a".array.sort!"a > b".array, A.filter!"a > 0".array.heapify );
    writefln("%s %s %s", d, w, m);


}
0