結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー hanorverhanorver
提出日時 2016-05-24 13:28:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,372 bytes
コンパイル時間 816 ms
コンパイル使用メモリ 81,464 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 11:49:06
合計ジャッジ時間 1,362 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

bool isBambooCol(int a, int b, int c) {
	// a,b,cが門松列かの判定
	if (a == b || a == c || b == c) return false;
	if (b < a && b < c) return true;
	if (b > a && b > c) return true;
	return false;
}

void calc() {
	int bamboo_no; // 竹の本数
	std::cin >> bamboo_no;

	// <竹の長さ, 個数>
	std::map<int, int> bamboo;
	for (int i = 0; i < bamboo_no; i++) {
		int bamboo_length;
		std::cin >> bamboo_length;
		bamboo[bamboo_length]++;
	}


	long long ans = 0;
	auto it = bamboo.begin(); // 1つ目のイテレータ
	auto jt = ++bamboo.begin(); // 2つ目のイテレータ
	if (jt == bamboo.end()) {
		std::cout << 0 << std::endl;
		return;
	}
	auto kt = ++(++bamboo.begin()); //3つ目のイテレータ

	while (kt != bamboo.end()) {
		it->second--;
		jt->second--;
		kt->second--;
		if(isBambooCol(jt->first, it->first, kt->first)) ans++;

		if (kt->second == 0) kt = bamboo.erase(kt);
		if (kt == bamboo.end()) break;
		if (jt->second == 0) {
			kt++;
			if (kt == bamboo.end()) break;
			jt = bamboo.erase(jt);
		}
		if (it->second == 0) {
			kt++;
			if (kt == bamboo.end()) break;
			jt++;
			it = bamboo.erase(it);
		}
	}

	std::cout << ans << std::endl;
}


int main() {
	int test_case;
	std::cin >> test_case;

	for (int i = 0; i < test_case; i++) {
		calc();
	}

	return 0;
}
0