結果

問題 No.1470 Mex Sum
ユーザー ytqm3
提出日時 2021-04-09 22:01:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 363 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 191,028 KB
最終ジャッジ日時 2025-01-20 14:23:45
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main()
{
  int64_t N,A,ans=0,cnt1=0,cnt2=0;
  std::cin>>N;
  for(int32_t i=0;i<N;i++)
  {
    std::cin>>A;
    if(A==1)
    {
      cnt1++;
    }
    if(A==2)
    {
      cnt2++;
    }
  }
  ans+=(N-cnt1)*(N-cnt1-1)/2;
  ans+=(cnt1*(N-cnt2-1)-cnt1*(cnt1-1)/2)*2;
  ans+=cnt1*cnt2*3;
  std::cout<<ans<<std::endl;
}
0