結果

問題 No.190 Dry Wet Moist
ユーザー commycommy
提出日時 2019-03-30 01:21:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,976 bytes
コンパイル時間 1,247 ms
コンパイル使用メモリ 89,616 KB
実行使用メモリ 13,412 KB
最終ジャッジ日時 2023-08-06 22:30:19
合計ジャッジ時間 4,017 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 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,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 37 ms
7,548 KB
testcase_13 AC 46 ms
8,064 KB
testcase_14 AC 35 ms
7,220 KB
testcase_15 AC 49 ms
8,472 KB
testcase_16 AC 62 ms
9,148 KB
testcase_17 AC 9 ms
4,536 KB
testcase_18 AC 31 ms
6,812 KB
testcase_19 AC 61 ms
9,128 KB
testcase_20 AC 43 ms
7,924 KB
testcase_21 AC 7 ms
4,380 KB
testcase_22 AC 69 ms
7,860 KB
testcase_23 AC 96 ms
13,412 KB
testcase_24 AC 91 ms
12,028 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 56 ms
9,296 KB
testcase_28 AC 27 ms
6,816 KB
testcase_29 AC 33 ms
7,424 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