結果

問題 No.190 Dry Wet Moist
ユーザー Yang33Yang33
提出日時 2018-07-30 23:46:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 2,944 bytes
コンパイル時間 1,785 ms
コンパイル使用メモリ 170,652 KB
実行使用メモリ 5,536 KB
最終ジャッジ日時 2023-10-13 09:59:07
合計ジャッジ時間 4,037 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 3 ms
4,352 KB
testcase_12 AC 20 ms
4,720 KB
testcase_13 AC 25 ms
4,916 KB
testcase_14 AC 19 ms
4,716 KB
testcase_15 AC 26 ms
4,880 KB
testcase_16 AC 33 ms
5,464 KB
testcase_17 AC 6 ms
4,348 KB
testcase_18 AC 16 ms
4,720 KB
testcase_19 AC 34 ms
5,440 KB
testcase_20 AC 23 ms
4,936 KB
testcase_21 AC 5 ms
4,348 KB
testcase_22 AC 38 ms
5,536 KB
testcase_23 AC 41 ms
5,408 KB
testcase_24 AC 39 ms
5,460 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 26 ms
4,920 KB
testcase_28 AC 13 ms
4,480 KB
testcase_29 AC 16 ms
4,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/07/30  Problem: yukicoder 190  / Link: http://yukicoder.me/problems/no/190  ----- */
/* ------問題------

kamipeipaa君は理系学生なので、実験が大好きです。今日はある湿気を持った2つの試料を合成する実験をしています。
kamipeipaa君は2N個の試料を持っています。i番目の試料の湿気は整数Aiで表されます。これらのうち2つを選んで合成するという作業をN回繰り返します。合成された物質の湿気は合成に用いた2つの試料の湿気の和で表されます。合成後の物質の湿気が負のときDry、正のときWet、ゼロのときはMoistと呼ばれます。合成後の物質は危険なので使ってはいけません。なお、当然のことながら合成に用いた試料はなくなります。

kamipeipaa君はこれから実験を行いますが、合成結果としてDryなもの、Wetなもの、Moistなものを最大どれだけ作ることが可能か気になっています。kamipeipaa君に教えてあげてください。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


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

	int N;  cin >> N;
	N *= 2;
	VL a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	SORT(a);
	auto dry = [&N](const VL& a) {
		int i = N - 1;
		int j = 0;
		int ret = 0;
		for (;j<i;) {
			if (a[i] + a[j] < 0) {
				ret++;
				i--; j++;
			}
			else {
				i--;
			}

		}
		return ret;
	};
	auto wet = [&N](const VL& a) {
		int i = N - 1;
		int j = 0;
		int ret = 0;
		for (; j<i;) {
			if (a[i] + a[j] > 0) {
				ret++;
				i--; j++;
			}
			else {
				j++;
			}

		}
		return ret;
	};
	auto moist = [&N](const VL& a) {
		int ret = 0;
		VL b(1e5 + 1, 0);
		int zero = 0;
		FOR(i, 0, N) {
			if (a[i] == 0)zero++;
			else if (a[i] < 0)b[-a[i]]++;
			else {
				if (b[a[i]]) {
					ret++;
					b[a[i]]--;
				}
			}
		}
		ret += zero / 2;
		return ret;
	};

	cout << dry(a) << " " << wet(a) << " " << moist(a) << endl;

	return 0;
}
0