結果

問題 No.190 Dry Wet Moist
ユーザー furafura
提出日時 2020-07-04 21:26:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 2,016 ms
コンパイル使用メモリ 208,540 KB
最終ジャッジ日時 2025-01-11 15:46:16
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:44:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |         int n; scanf("%d",&n); n*=2;
      |                ~~~~~^~~~~~~~~
main.cpp:46:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |         rep(i,n) scanf("%d",&a[i]);
      |                  ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int solve1(vector<int> a){
	int n=a.size();
	sort(a.rbegin(),a.rend());

	int res=0,idx=n-1;
	rep(i,n){
		while(idx>i && a[i]+a[idx]<=0){
			idx--;
		}
		if(idx>i && a[i]+a[idx]>0){
			res++;
			idx--;
		}
	}
	return res;
}

int solve2(vector<int> a){
	int n=a.size();
	map<int,int> f;
	rep(i,n) ++f[a[i]];

	int res=0;
	for(auto it=f.begin();it!=f.end();++it){
		auto [x,c]=*it;
		if(x>0) break;
		if(x==0){
			res+=c/2;
		}
		else if(f.count(-x)>0) {
			res+=min(c,f[-x]);
		}
	}
	return res;
}

int main(){
	int n; scanf("%d",&n); n*=2;
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	rep(i,n) a[i]*=-1;
	printf("%d ",solve1(a));
	rep(i,n) a[i]*=-1;
	printf("%d %d\n",solve1(a),solve2(a));

	return 0;
}
0