結果

問題 No.1470 Mex Sum
ユーザー terry_u16
提出日時 2021-04-09 22:03:12
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 655 bytes
コンパイル時間 1,010 ms
コンパイル使用メモリ 119,936 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-25 05:30:30
合計ジャッジ時間 3,838 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> a(n);

    for (size_t i = 0; i < n; i++)
    {
        std::cin >> a[i];
    }

    long long one, two, more;
    one = 0;
    two = 0;

    for (auto ai : a)
    {
        if (ai == 1)
        {
            one++;
        }
        else if (ai == 2)
        {
            two++;
        }
    }

    more = n - one - two;

    long long result = 0;

    result += (two + more) * (two + more - 1) / 2;
    result += 2 * ((one + more) * (one + more - 1) / 2 - more * (more - 1) / 2);
    result += 3 * one * two;
    std::cout << result << std::endl;
}
0