結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー kpinkcatkpinkcat
提出日時 2023-10-26 10:22:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,936 bytes
コンパイル時間 2,596 ms
コンパイル使用メモリ 214,200 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 10:23:00
合計ジャッジ時間 3,576 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
    }
}
0