結果

問題 No.190 Dry Wet Moist
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-09-04 16:18:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,159 bytes
コンパイル時間 497 ms
コンパイル使用メモリ 65,568 KB
実行使用メモリ 31,616 KB
最終ジャッジ日時 2024-04-27 16:29:44
合計ジャッジ時間 4,237 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 241 ms
31,488 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
6,940 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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(x);
        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(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