結果

問題 No.110 しましまピラミッド
ユーザー kotatsugame
提出日時 2017-08-10 04:53:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 885 bytes
コンパイル時間 918 ms
コンパイル使用メモリ 78,756 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-31 11:34:19
合計ジャッジ時間 1,921 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<queue>
using namespace std;
priority_queue<int>W,B,P,Q;
int n,a,now,cnt,ans;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a,W.push(a);
	P=W;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a,B.push(a);
	Q=B;
	bool f=true;
	now=114514;
	while(f?!W.empty():!B.empty())
	{
		if(f)
		{
			while(!W.empty()&&W.top()>=now)W.pop();
			if(!W.empty())now=W.top(),W.pop(),cnt++;
			else break;
		}
		else
		{
			while(!B.empty()&&B.top()>=now)B.pop();
			if(!B.empty())now=B.top(),B.pop(),cnt++;
			else break;
		}
		f=!f;
	}
	ans=cnt,cnt=0,now=114514,f=false;
	W=P,B=Q;
	while(f?!W.empty():!B.empty())
	{
		if(f)
		{
			while(!W.empty()&&W.top()>=now)W.pop();
			if(!W.empty())now=W.top(),W.pop(),cnt++;
			else break;
		}
		else
		{
			while(!B.empty()&&B.top()>=now)B.pop();
			if(!B.empty())now=B.top(),B.pop(),cnt++;
			else break;
		}
		f=!f;
	}
	cout<<max(ans,cnt)<<endl;
}
0