結果

問題 No.190 Dry Wet Moist
ユーザー izuru_matsuura
提出日時 2016-11-01 18:04:59
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 1,442 bytes
コンパイル時間 1,901 ms
コンパイル使用メモリ 164,512 KB
実行使用メモリ 17,872 KB
最終ジャッジ日時 2024-06-12 04:51:58
合計ジャッジ時間 3,917 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

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