結果

問題 No.1470 Mex Sum
コンテスト
ユーザー Noboru2020
提出日時 2021-04-09 21:32:09
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 395 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,096 ms
コンパイル使用メモリ 194,328 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-03-11 09:07:30
合計ジャッジ時間 3,879 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N;cin>>N;
  vector<int>vec(N);
  map<int,int>mp;
  for(int &i:vec){
    cin>>i;
    mp[i]++;
  }
  int ans=0,memo=0;
  ans+=mp[1]*mp[2]*3;
  memo+=mp[1]*mp[2];
  ans+=(mp[1]*(mp[1]-1)/2+mp[1]*(N-mp[1]-mp[2]))*2;
  memo+=(mp[1]*(mp[1]-1)/2+mp[1]*(N-mp[1]-mp[2]));
  ans+=N*(N-1)/2-memo;
  cout<<ans<<endl;
}
0