結果

問題 No.190 Dry Wet Moist
ユーザー kk
提出日時 2021-03-10 19:57:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,133 bytes
コンパイル時間 3,165 ms
コンパイル使用メモリ 204,132 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 14:38:51
合計ジャッジ時間 4,719 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 30 ms
6,940 KB
testcase_13 AC 37 ms
6,940 KB
testcase_14 AC 29 ms
6,944 KB
testcase_15 AC 41 ms
6,940 KB
testcase_16 AC 51 ms
6,940 KB
testcase_17 AC 8 ms
6,944 KB
testcase_18 AC 25 ms
6,940 KB
testcase_19 AC 50 ms
6,940 KB
testcase_20 AC 35 ms
6,944 KB
testcase_21 AC 6 ms
6,940 KB
testcase_22 AC 59 ms
6,944 KB
testcase_23 AC 63 ms
6,944 KB
testcase_24 AC 61 ms
6,944 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 3 ms
6,944 KB
testcase_27 AC 39 ms
6,944 KB
testcase_28 AC 18 ms
6,944 KB
testcase_29 AC 23 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int wet(const vector<int> &a) {
  vector<int> x, y;

  for (int t: a) {
    if (t > 0) x.push_back(t);
    else y.push_back(t);
  }

  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  int ret = 0;
  int j = 0;
  for (int i = x.size() - 1; i >= 0; i--) {
    while (j < y.size() && x[i] + y[j] <= 0)
      ++j;
    if (j < y.size()) {
      ++j;
      ++ret;
    } else {
      ret += (i+1) / 2;
      break;
    }
  }
  return ret;
}

int dry(const vector<int> &a) {
  vector<int> b;
  for (int t: a)
    b.push_back(-t);
  return wet(b);
}

int moist(const vector<int> &a) {
  int z = 0;
  vector<int> pos(1e5 + 1), neg(1e5 + 1);

  for (int x: a) {
    if (x == 0) ++z;
    else if (x > 0) ++pos[x];
    else ++neg[abs(x)];
  }

  int ret = z / 2;
  for (int i = 1; i <= 1e5; i++) {
    ret += min(pos[i], neg[i]);
  }

  return ret;
}

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

  int n;
  cin >> n;
  n *= 2;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  cout << dry(a) << " " << wet(a) << " " << moist(a) << endl;
  
  return 0;
}
0