結果

問題 No.190 Dry Wet Moist
ユーザー ttkkggwwttkkggww
提出日時 2022-08-25 14:09:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 718 ms / 2,000 ms
コード長 1,018 bytes
コンパイル時間 4,781 ms
コンパイル使用メモリ 266,392 KB
実行使用メモリ 17,280 KB
最終ジャッジ日時 2024-04-20 22:49:20
合計ジャッジ時間 12,367 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 7 ms
6,940 KB
testcase_08 AC 5 ms
6,940 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 4 ms
6,944 KB
testcase_12 AC 380 ms
10,624 KB
testcase_13 AC 465 ms
11,904 KB
testcase_14 AC 357 ms
10,496 KB
testcase_15 AC 494 ms
12,416 KB
testcase_16 AC 655 ms
13,952 KB
testcase_17 AC 76 ms
6,944 KB
testcase_18 AC 300 ms
9,472 KB
testcase_19 AC 661 ms
13,824 KB
testcase_20 AC 464 ms
11,520 KB
testcase_21 AC 53 ms
6,944 KB
testcase_22 AC 669 ms
15,744 KB
testcase_23 AC 704 ms
17,280 KB
testcase_24 AC 718 ms
15,744 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 431 ms
13,184 KB
testcase_28 AC 191 ms
9,088 KB
testcase_29 AC 247 ms
10,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
int n;
vector<ll> a;

void solve(){
	sort(a.begin(),a.end());
	for(auto &i:a)cerr<<i<<' ';cerr<<endl;
	for(int _ = 0;_ < 2; _++){
		for(int i = 0;i<n*2;i++)a[i] *= -1;
		multiset<int> ng,pg,zero;
		for(int i = 0;i<n*2;i++){
			if(a[i]<0)ng.insert(a[i]);
			else if(a[i]>0)pg.insert(a[i]);
			else zero.insert(a[i]);
		}
		int ans =0;
		for(auto &i:ng){
			auto it = pg.upper_bound(-i);
			if(pg.end()!=it){
				pg.erase(it);
				ans++;
			}
		}
		int zerocnt = zero.size();
		int pgcnt = pg.size();
		ans += min(zerocnt,pgcnt);
		pgcnt -= min(zerocnt,pgcnt);
		ans += pgcnt/2;
		cout<<ans<<' ';
	}
	map<ll,ll> mp;
	for(int i = 0;i<n*2;i++){
		mp[a[i]]++;
		mp[-a[i]]+=0;
	}
	ll ans =0;
	for(auto &i:mp){
		ans += min(i.second,mp[-i.first]);
		
	}
	cout<<ans/2<<endl;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n;
	a = vector<ll>(n*2);
	for(auto &i:a)cin >> i;
	solve();
}
0