結果

問題 No.1470 Mex Sum
ユーザー Manuel1024
提出日時 2021-04-27 22:19:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 423 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 69,292 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-06 17:11:52
合計ジャッジ時間 4,884 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14 WA * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &p: a) cin >> p;
    
    int cnt1 = 0, cnt2 = 0;
    for(auto &p: a){
        if(p == 1) cnt1++;
        else if(p == 2) cnt2++;
    }

    ll ans = (ll)n*(n-1)/2;
    ans += (ll)cnt1*(cnt1-1)/2;
    ans += (ll)cnt1*cnt2*2;
    cout << ans << endl;
    return 0;
}
0