結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  kpinkcat | 
| 提出日時 | 2023-10-26 10:22:56 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,936 bytes | 
| コンパイル時間 | 2,120 ms | 
| コンパイル使用メモリ | 206,360 KB | 
| 最終ジャッジ日時 | 2025-02-17 13:48:36 | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | WA * 4 | 
ソースコード
#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<math.h>
#include<bitset>
using ll = long long;
using namespace std;
ll mod = 1e9+7;
uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    dividend %= mod;
    divisor  *= i;
  }
  return dividend / divisor;
}
int main(){
    int t;
    cin >> t;
    
    for (int i = 0; i < t; i++) {
        int t1, ans = 0, al1 = 0;
        cin >> t1;
        map<int, int> mp;
        for (int j = 0; j < t1; j++){
            int t2;
            cin >> t2;
            mp[t2]++;
        }
        vector<int> mul;
        for (auto itr = mp.begin(); itr != mp.end(); itr++){
            if (itr->second > 1) {
                mul.push_back(itr->second - 1);
            } else al1++;
        }
        sort(mul.begin(), mul.end(), greater());
        while (mul.size() >= 3){
            int t3 = mul[mul.size()-1];
            ans += t3;
            mul[0] -= t3;
            mul[1] -= t3;
            mul.erase(mul.end()-1);
            al1++;
        }
        if (mul.size()==2){
            if (mul[1] >= al1){
                ans += al1;
                cout << ans << endl;
                continue;
            } else {
                ans += mul[1];
                al1 -= mul[1];
                mul[0] -= mul[1];
                al1++;
            }
        }
        if (mul.size()== 1){
            if (mul[0]*2 <= al1){
                ans += mul[0];
                al1 -= mul[0]*2;
                al1++;
            } else {
                ans += al1/2;
                cout << ans << endl;
                continue;
            }
        }
        ans += al1/3;
        cout << ans << endl;
    }
}
            
            
            
        