結果

問題 No.190 Dry Wet Moist
ユーザー tottoripapertottoripaper
提出日時 2015-07-02 19:05:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,079 bytes
コンパイル時間 585 ms
コンパイル使用メモリ 63,640 KB
実行使用メモリ 4,416 KB
最終ジャッジ日時 2023-09-22 05:34:45
合計ジャッジ時間 2,411 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 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,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 23 ms
4,380 KB
testcase_13 AC 28 ms
4,388 KB
testcase_14 AC 22 ms
4,376 KB
testcase_15 AC 31 ms
4,380 KB
testcase_16 AC 37 ms
4,416 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 19 ms
4,376 KB
testcase_19 AC 39 ms
4,408 KB
testcase_20 AC 26 ms
4,380 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 40 ms
4,380 KB
testcase_23 AC 47 ms
4,376 KB
testcase_24 AC 42 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 29 ms
4,376 KB
testcase_28 AC 14 ms
4,376 KB
testcase_29 AC 19 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

int c1[100001], c_1[100001], c0;
std::vector<int> v;                 

int count(){
    int n = v.size(), res = 0;

    for(int i=n-1,j=0;i>=0;i--){
        while(j < i && v[j] + v[i] <= 0){j += 1;}
        if(j >= i){break;}
        // printf("%d, %d, %d, %d\n", i, j, v[i], v[j]);
        res += 1;
        j += 1;
    }

    return res;
}

int main(){
    int N;
    scanf("%d", &N);

    c0 = 0;
    for(int i=0;i<2*N;i++){
        int a;
        scanf("%d", &a);

        if(a > 0){
            c1[a] += 1;
        }else if(a == 0){
            c0 += 1;
        }else{
            c_1[-a] += 1;
        }

        v.push_back(a);
    }

    int dry = 0, wet = 0, moist = c0 / 2;
    for(int i=1;i<=100000;i++){
        moist += std::min(c1[i], c_1[i]);
    }

    std::sort(v.begin(), v.end());
    wet = count();
    
    std::reverse(v.begin(), v.end());
    std::transform(v.begin(), v.end(), v.begin(), std::negate<int>());

    dry = count();

    printf("%d %d %d\n", dry, wet, moist);
}
0