結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-07-02 14:02:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 5,000 ms |
| コード長 | 1,029 bytes |
| コンパイル時間 | 858 ms |
| コンパイル使用メモリ | 79,668 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-07 22:14:10 |
| 合計ジャッジ時間 | 1,284 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | int t; scanf("%d", &t);
| ~~~~~^~~~~~~~~~
main.cpp:29:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:32:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
32 | int x; scanf("%d", &x);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};
int nya(priority_queue<int> que) {
if(que.size() < 3) { return 0; }
int res = 0;
while(!que.empty()) {
int x = que.top(); que.pop();
int y = que.top(); que.pop();
int z = que.top(); que.pop();
if(z == 0) { break; }
res++;
que.push(x-1);
que.push(y-1);
que.push(z-1);
}
return res;
}
int main(void) {
int t; scanf("%d", &t);
for(int times : range(t)) {
int n; scanf("%d", &n);
map<int, int> kort;
for(int i : range(n)) {
int x; scanf("%d", &x);
kort[x]++;
}
priority_queue<int> que;
for(auto kv : kort) {
que.push(kv.second);
}
int res = nya(que);
printf("%d\n", res);
}
return 0;
}