結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0; i<(n); i++)

ll N;
ll c1,c2,cx;

int main(){
  cin>>N;
  c1=c2=cx=0;
  rep(i,N){
    int a; cin>>a;
    if(a==1) c1++;
    if(a==2) c2++;
    if(a>2) cx++;
  }
  ll ans=0;
  ans += c1*(c1-1)/2 *2;
  ans += c1*c2 *3;
  ans += c1*cx *2;
  ans += c2*(c2-1)/2 *1;
  ans += c2*cx *1;
  ans += cx*(cx-1)/2 *1;
  cout<<ans<<"\n";
  return 0;
}
0