結果

問題 No.190 Dry Wet Moist
ユーザー MisterMister
提出日時 2020-09-04 16:26:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 1,836 bytes
コンパイル時間 639 ms
コンパイル使用メモリ 77,208 KB
実行使用メモリ 22,172 KB
最終ジャッジ日時 2023-08-17 07:05:46
合計ジャッジ時間 3,917 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 81 ms
13,832 KB
testcase_13 AC 101 ms
16,424 KB
testcase_14 AC 75 ms
13,636 KB
testcase_15 AC 112 ms
17,560 KB
testcase_16 AC 150 ms
21,524 KB
testcase_17 AC 16 ms
5,624 KB
testcase_18 AC 63 ms
11,692 KB
testcase_19 AC 152 ms
21,220 KB
testcase_20 AC 95 ms
15,572 KB
testcase_21 AC 10 ms
5,108 KB
testcase_22 AC 155 ms
22,132 KB
testcase_23 AC 161 ms
22,116 KB
testcase_24 AC 160 ms
22,172 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 99 ms
15,296 KB
testcase_28 AC 41 ms
8,620 KB
testcase_29 AC 53 ms
10,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>

void solve() {
    int n;
    std::cin >> n;
    n *= 2;

    std::multiset<int> org;
    while (n--) {
        int x;
        std::cin >> x;
        org.insert(x);
    }

    // Dry
    {
        auto s = org;

        int cnt = 0;
        auto it = s.begin();
        while (it != s.end()) {
            auto x = *it;
            it = s.erase(it);

            // x + y < 0 <-> y < -x
            auto nit = s.lower_bound(-x);
            if (nit == s.begin()) continue;

            ++cnt;
            --nit;

            if (it == nit) {
                it = s.erase(nit);
            } else {
                s.erase(nit);
            }
        }

        std::cout << cnt << " ";
    }

    // Wet
    {
        auto s = org;

        int cnt = 0;
        auto it = s.begin();
        while (it != s.end()) {
            auto x = *it;
            it = s.erase(it);

            // x + y > 0 <-> y > -x
            auto nit = s.upper_bound(-x);
            if (nit == s.end()) continue;

            ++cnt;

            if (it == nit) {
                it = s.erase(nit);
            } else {
                s.erase(nit);
            }
        }

        std::cout << cnt << " ";
    }

    // Moist
    {
        auto s = org;

        int cnt = 0;
        auto it = s.begin();
        while (it != s.end()) {
            auto x = *it;
            it = s.erase(it);

            // x + y = 0 <-> y = -x
            auto nit = s.find(-x);
            if (nit == s.end()) continue;

            ++cnt;

            if (it == nit) {
                it = s.erase(nit);
            } else {
                s.erase(nit);
            }
        }

        std::cout << cnt << "\n";
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0