結果

問題 No.190 Dry Wet Moist
ユーザー h_nosonh_noson
提出日時 2016-06-10 01:01:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,583 bytes
コンパイル時間 779 ms
コンパイル使用メモリ 73,052 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 15:15:13
合計ジャッジ時間 3,091 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 31 ms
5,376 KB
testcase_13 AC 41 ms
5,376 KB
testcase_14 AC 30 ms
5,376 KB
testcase_15 AC 43 ms
5,376 KB
testcase_16 AC 57 ms
5,376 KB
testcase_17 AC 8 ms
5,376 KB
testcase_18 AC 25 ms
5,376 KB
testcase_19 AC 53 ms
5,376 KB
testcase_20 AC 36 ms
5,376 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 AC 65 ms
5,376 KB
testcase_23 AC 70 ms
5,376 KB
testcase_24 AC 71 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 46 ms
5,376 KB
testcase_28 AC 20 ms
5,376 KB
testcase_29 AC 26 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)
#define INF (int)1e8
#define MOD (int)(1e9+7)

typedef long long ll;

int main(void) {
    int i, n;
    cin >> n;
    vector<int> pos, neg;
    int zero = 0;
    rep (i,n*2) {
        int a;
        cin >> a;
        if (a > 0)
            pos.push_back(a);
        else if (a < 0)
            neg.push_back(a);
        else
            zero++;
    }
    sort(pos.begin(),pos.end());
    sort(neg.begin(),neg.end(),greater<int>{});
    // dry
    int ans;
    ans = i = 0;
    for (auto x : pos) {
        while (i < neg.size() && neg[i] + x >= 0) i++;
        if (i == neg.size()) break;
        ans++; i++;
    }
    int v;
    v = min((int)neg.size()-ans,zero);
    ans += v + max(0,(int)neg.size()-v-ans)/2;
    cout << ans << " ";

    // wet
    ans = i = 0;
    for (auto x : neg) {
        while (i < pos.size() && pos[i] + x <= 0) i++;
        if (i == pos.size()) break;
        ans++; i++;
    }
    v = min((int)pos.size()-ans,zero);
    ans += v + max(0,(int)pos.size()-v-ans)/2;
    cout << ans << " ";

    // moist
    int j;
    ans = zero / 2;
    i = j = 0;
    while (i < pos.size() && j < neg.size()) {
        if (pos[i] + neg[j] == 0)
            ans++, i++, j++;
        else if (pos[i] + neg[j] > 0)
            j++;
        else
            i++;
    }
    cout << ans << endl;
    return 0;
}
0