結果

問題 No.190 Dry Wet Moist
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-09-04 16:21:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 322 ms / 2,000 ms
コード長 1,177 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 62,876 KB
実行使用メモリ 31,488 KB
最終ジャッジ日時 2024-04-27 16:29:49
合計ジャッジ時間 4,644 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 139 ms
18,944 KB
testcase_13 AC 183 ms
22,912 KB
testcase_14 AC 126 ms
18,432 KB
testcase_15 AC 212 ms
24,704 KB
testcase_16 AC 283 ms
30,464 KB
testcase_17 AC 23 ms
6,940 KB
testcase_18 AC 96 ms
15,744 KB
testcase_19 AC 268 ms
30,336 KB
testcase_20 AC 163 ms
21,504 KB
testcase_21 AC 14 ms
6,940 KB
testcase_22 AC 310 ms
31,360 KB
testcase_23 AC 322 ms
31,488 KB
testcase_24 AC 316 ms
31,488 KB
testcase_25 AC 1 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 176 ms
20,992 KB
testcase_28 AC 65 ms
11,264 KB
testcase_29 AC 90 ms
13,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <ciso646>
#include <cstdlib>
#include <iostream>
#include <set>


typedef int Moisture;
typedef std::multiset<Moisture> Reactants;


int moist(Reactants xs) {
    int ans = 0;
    while (not xs.empty())
    {
        auto x = *xs.begin();
        xs.erase(xs.begin());
        auto itr = xs.find(-x);
        if (itr != xs.end())
        {
            ans++;
            xs.erase(itr);
        }
    }
    return ans;
}


int wet(Reactants xs) {
    int ans = 0;
    while (not xs.empty())
    {
        auto x = *xs.rbegin();
        xs.erase(xs.find(x));
        auto itr = xs.lower_bound(1 - x);
        if (itr != xs.end())
        {
            ans++;
            xs.erase(itr);
        }
    }
    return ans;
}


int dry(const Reactants& xs) {
    Reactants ys;
    for (auto x : xs)
    {
        ys.insert(-x);
    }
    return wet(ys);
}


int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n;
    std::cin >> n;
    Reactants xs;
    for (auto i = 0; i < 2 * n; i++)
    {
        Moisture x;
        std::cin >> x;
        xs.insert(x);
    }
    std::cout << dry(xs) << ' ' << wet(xs) << ' ' << moist(xs) << std::endl;
}
0