結果

問題 No.190 Dry Wet Moist
ユーザー ふーらくたるふーらくたる
提出日時 2016-07-18 02:43:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,214 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 59,552 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 15:10:17
合計ジャッジ時間 2,311 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,948 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 20 ms
6,944 KB
testcase_13 AC 23 ms
6,940 KB
testcase_14 AC 16 ms
6,940 KB
testcase_15 AC 24 ms
6,944 KB
testcase_16 AC 30 ms
6,944 KB
testcase_17 AC 5 ms
6,944 KB
testcase_18 AC 15 ms
6,944 KB
testcase_19 AC 30 ms
6,944 KB
testcase_20 AC 21 ms
6,940 KB
testcase_21 AC 4 ms
6,944 KB
testcase_22 AC 34 ms
6,940 KB
testcase_23 AC 36 ms
6,940 KB
testcase_24 AC 35 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 26 ms
6,940 KB
testcase_28 AC 12 ms
6,940 KB
testcase_29 AC 15 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int kMAX_N = 100010;
const int kMAX_ABS_A = 100010;
int A[kMAX_N * 2];
int N;

int pos_count[kMAX_ABS_A], neg_count[kMAX_ABS_A];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;

    for (int i = 0; i < 2 * N; i++) {
        cin >> A[i];
        if (A[i] >= 0) pos_count[A[i]]++;
        else neg_count[-A[i]]++;
    }

    sort(A, A + 2 * N);

    int left = 0, right = 2 * N - 1, wet = 0, dry = 0, moist = 0;
    while (left < right) {
        while (left < right && A[left] + A[right] <= 0) {
            left++;
        }
        if (left < right) {
            wet++;
        }
        left++;
        right--;
    }

    left = 0, right = 2 * N - 1;
    while (left < right) {
        while (left < right && A[left] + A[right] >= 0) {
            right--;
        }
        if (left < right) {
            dry++;
        }
        left++;
        right--;
    }

    for (int i = 0; i < kMAX_ABS_A; i++) {
        if (i == 0) moist += pos_count[i] / 2;
        else {
            moist += min(pos_count[i], neg_count[i]);
        }
    }
    cout << dry << " " << wet << " " << moist << endl;

    return 0;
}
0