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