結果

問題 No.190 Dry Wet Moist
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-09-04 16:21:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 1,177 bytes
コンパイル時間 2,305 ms
コンパイル使用メモリ 60,048 KB
実行使用メモリ 31,676 KB
最終ジャッジ日時 2023-08-09 22:08:50
合計ジャッジ時間 6,140 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 117 ms
18,884 KB
testcase_13 AC 170 ms
22,924 KB
testcase_14 AC 114 ms
18,328 KB
testcase_15 AC 182 ms
24,616 KB
testcase_16 AC 259 ms
30,548 KB
testcase_17 AC 21 ms
6,724 KB
testcase_18 AC 92 ms
15,696 KB
testcase_19 AC 248 ms
30,128 KB
testcase_20 AC 143 ms
21,636 KB
testcase_21 AC 14 ms
5,520 KB
testcase_22 AC 280 ms
31,436 KB
testcase_23 AC 280 ms
31,676 KB
testcase_24 AC 289 ms
31,460 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 161 ms
21,116 KB
testcase_28 AC 56 ms
11,204 KB
testcase_29 AC 74 ms
13,472 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