結果

問題 No.190 Dry Wet Moist
ユーザー ciel
提出日時 2015-04-22 03:56:36
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 757 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 44,032 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 00:02:41
合計ジャッジ時間 1,780 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |         scanf("%d",&N),N*=2;
      |         ~~~~~^~~~~~~~~
main.cpp:38:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |         for(int i=0;i<N;i++)scanf("%d",&v[i]);
      |                             ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int dry(vector<int> &v){
	int R=0,lo=0,hi=v.size()-1;
	for(;lo<hi;R++,lo++,hi--){
		for(;lo<hi;hi--)if(v[lo]+v[hi]<0)break;
		if(lo==hi)break;
		
	}
	return R;
}

int wet(vector<int> &v){
	int R=0,lo=0,hi=v.size()-1;
	for(;lo<hi;R++,lo++,hi--){
		for(;lo<hi;lo++)if(v[lo]+v[hi]>0)break;
		if(lo==hi)break;
	}
	return R;
}

int moist(vector<int> &v){
	int R=0,lo=0,hi=v.size()-1;
	for(;lo<hi;v[lo]+v[hi]==0?(R++,hi--):1,lo++){
		for(;lo<hi;hi--)if(v[lo]+v[hi]<=0)break;
		if(lo==hi)break;
	}
	return R;
}

int main(){
	int N;
	scanf("%d",&N),N*=2;
	vector<int>v(N);
	for(int i=0;i<N;i++)scanf("%d",&v[i]);
	sort(v.begin(),v.end());
	printf("%d %d %d\n",dry(v),wet(v),moist(v));
}
0