結果

問題 No.190 Dry Wet Moist
ユーザー face4face4
提出日時 2019-02-13 10:06:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,076 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 77,464 KB
実行使用メモリ 4,936 KB
最終ジャッジ日時 2023-10-11 11:06:29
合計ジャッジ時間 3,325 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 37 ms
4,480 KB
testcase_13 AC 46 ms
4,364 KB
testcase_14 AC 35 ms
4,484 KB
testcase_15 AC 50 ms
4,356 KB
testcase_16 AC 62 ms
4,624 KB
testcase_17 AC 9 ms
4,348 KB
testcase_18 AC 29 ms
4,352 KB
testcase_19 AC 61 ms
4,620 KB
testcase_20 AC 43 ms
4,364 KB
testcase_21 AC 7 ms
4,348 KB
testcase_22 AC 70 ms
4,632 KB
testcase_23 AC 78 ms
4,632 KB
testcase_24 AC 77 ms
4,936 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 50 ms
4,484 KB
testcase_28 AC 24 ms
4,372 KB
testcase_29 AC 29 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int n;
    cin >> n;

    vector<int> v(2*n), plus(100001, 0), minus(100001, 0);
    int z = 0;
    for(int i = 0; i < 2*n; i++){
        cin >> v[i];
        if(v[i] > 0)        plus[v[i]]++;
        else if(v[i] < 0)   minus[-v[i]]++;
        else                z++;
    }

    sort(v.begin(), v.end());
    
    int d = 0, w = 0, m = 0;

    // dry
    int r = lower_bound(v.begin(), v.end(), 0)-v.begin();
    int l = r-1, discard = 0;
    while(0 <= l && r < 2*n){
        if(v[l]+v[r] < 0)   d++, l--, r++;
        else                l--, discard++;
    }
    d += (l+1+discard)/2;

    // wet
    r = upper_bound(v.begin(), v.end(), 0)-v.begin();
    l = r-1; discard = 0;
    while(0 <= l && r < 2*n){
        if(v[l]+v[r] > 0)   w++, l--, r++;
        else                r++, discard++;
    }
    w += (2*n-1-r+1+discard)/2;

    // moist
    m += z/2;
    for(int i = 1; i < 100001; i++) m += min(plus[i], minus[i]);

    printf("%d %d %d\n", d, w, m);

    return 0;
}
0