結果

問題 No.110 しましまピラミッド
ユーザー lapilapi
提出日時 2019-03-28 08:47:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,808 bytes
コンパイル時間 1,120 ms
コンパイル使用メモリ 112,788 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 04:09:14
合計ジャッジ時間 2,432 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int N1; cin >> N1;
	priority_queue<int> W;
	for (int i = 0; i < N1; i++) {
		int tmp; cin >> tmp;
		W.push(tmp);
	}
	int N2; cin >> N2;
	priority_queue<int> B;
	for (int i = 0; i < N2; i++) {
		int tmp; cin >> tmp;
		B.push(tmp);
	}

	int fw = 0;
	bool color = 1; // 1 : 次に乗せる色は白
	int under = INF;
	bool flag = true;
	priority_queue<int> tmpW = W;
	priority_queue<int> tmpB = B;
	while (flag) {
		flag = false;
		if (color) {
			while (!tmpW.empty() && tmpW.top() >= under) tmpW.pop();
			if (!tmpW.empty()) {
				under = tmpW.top();
				tmpW.pop();
				fw++;
				color = false;
				flag = true;
			}
		}
		else {
			while (!tmpB.empty() && tmpB.top() >= under) tmpB.pop();
			if (!tmpB.empty()) {
				under = tmpB.top();
				tmpB.pop();
				fw++;
				color = true;
				flag = true;
			}
		}
	}


	int fb = 0;
	color = 0; // 1 : 次に乗せる色は白
	under = INF;
	flag = true;
	tmpW = W;
	tmpB = B;
	while (flag) {
		flag = false;
		if (color) {
			while (!tmpW.empty() && tmpW.top() >= under) tmpW.pop();
			if (!tmpW.empty()) {
				under = tmpW.top();
				tmpW.pop();
				fb++;
				color = false;
				flag = true;
			}
		}
		else {
			while (!tmpB.empty() && tmpB.top() >= under) tmpB.pop();
			if (!tmpB.empty()) {
				under = tmpB.top();
				tmpB.pop();
				fb++;
				color = true;
				flag = true;
			}
		}
	}

	cout << max(fw, fb) << endl;

	return 0;
}
0