結果

問題 No.190 Dry Wet Moist
ユーザー commycommy
提出日時 2019-03-30 01:21:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,976 bytes
コンパイル時間 904 ms
コンパイル使用メモリ 89,508 KB
実行使用メモリ 13,428 KB
最終ジャッジ日時 2024-04-24 16:55:46
合計ジャッジ時間 3,309 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 34 ms
7,424 KB
testcase_13 AC 41 ms
8,176 KB
testcase_14 AC 30 ms
7,340 KB
testcase_15 AC 47 ms
8,576 KB
testcase_16 AC 59 ms
9,372 KB
testcase_17 AC 8 ms
5,376 KB
testcase_18 AC 27 ms
7,040 KB
testcase_19 AC 57 ms
9,344 KB
testcase_20 AC 39 ms
7,936 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 AC 65 ms
8,036 KB
testcase_23 AC 87 ms
13,428 KB
testcase_24 AC 85 ms
12,260 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 51 ms
9,472 KB
testcase_28 AC 24 ms
7,040 KB
testcase_29 AC 30 ms
7,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a, b;
    int zero = 0;
    REP(i, 0, 2 * n) {
        int v;
        cin >> v;
        if (v < 0) {
            a.push_back(-v);
        } else if (v > 0) {
            b.push_back(v);
        } else {
            zero++;
        }
    }
    sort(rbegin(a), rend(a));
    sort(rbegin(b), rend(b));
    auto Wet = [&]() -> int {
        int ans = 0;
        int j = 0;
        REP(i, 0, b.size()) {
            while (j < a.size() && b[i] <= a[j]) {
                j++;
            }
            if (j >= a.size()) {
                int rest = b.size() - i;
                int m = min(rest, zero);
                ans += m;
                rest -= m;
                ans += rest / 2;
                break;
            }
            ans++;
            j++;
        }
        return ans;
    };
    auto Dry = [&]() -> int {
        swap(a, b);
        int res = Wet();
        swap(a, b);
        return res;
    };
    auto Moist = [&]() -> int {
        int res = zero / 2;
        map<int, int> ma, mb;
        REP (i, 0, a.size()) {
            ma[a[i]]++;
        }
        REP (i, 0, b.size()) {
            mb[b[i]]++;
        }
        for (auto &it : ma) {
            res += min(it.second, mb[it.first]);
        }
        return res;
    };
    cout << Dry() << " " << Wet() << " " << Moist() << endl;
    return 0;
}
0