結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  hanorver | 
| 提出日時 | 2016-05-24 13:22:12 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,323 bytes | 
| コンパイル時間 | 933 ms | 
| コンパイル使用メモリ | 82,364 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-07 05:47:26 | 
| 合計ジャッジ時間 | 1,699 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | WA * 4 | 
ソースコード
#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--;
		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;
}
            
            
            
        