結果

問題 No.1470 Mex Sum
ユーザー saxofone111saxofone111
提出日時 2021-04-10 00:03:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,154 bytes
コンパイル時間 2,096 ms
コンパイル使用メモリ 204,748 KB
実行使用メモリ 4,924 KB
最終ジャッジ日時 2023-09-07 19:03:56
合計ジャッジ時間 6,154 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 6 ms
4,380 KB
testcase_03 AC 6 ms
4,376 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 6 ms
4,376 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 50 ms
4,600 KB
testcase_13 AC 49 ms
4,644 KB
testcase_14 AC 49 ms
4,652 KB
testcase_15 AC 51 ms
4,720 KB
testcase_16 AC 49 ms
4,728 KB
testcase_17 AC 49 ms
4,788 KB
testcase_18 AC 48 ms
4,764 KB
testcase_19 AC 49 ms
4,924 KB
testcase_20 AC 49 ms
4,596 KB
testcase_21 AC 51 ms
4,772 KB
testcase_22 AC 51 ms
4,588 KB
testcase_23 AC 51 ms
4,780 KB
testcase_24 AC 52 ms
4,636 KB
testcase_25 AC 50 ms
4,788 KB
testcase_26 AC 52 ms
4,636 KB
testcase_27 AC 51 ms
4,720 KB
testcase_28 AC 51 ms
4,700 KB
testcase_29 AC 51 ms
4,924 KB
testcase_30 AC 51 ms
4,724 KB
testcase_31 AC 50 ms
4,652 KB
testcase_32 AC 50 ms
4,636 KB
testcase_33 AC 50 ms
4,764 KB
testcase_34 AC 49 ms
4,780 KB
testcase_35 AC 51 ms
4,636 KB
testcase_36 AC 51 ms
4,604 KB
testcase_37 AC 49 ms
4,692 KB
testcase_38 AC 32 ms
4,804 KB
testcase_39 AC 32 ms
4,784 KB
testcase_40 AC 41 ms
4,648 KB
testcase_41 AC 41 ms
4,924 KB
testcase_42 AC 41 ms
4,600 KB
testcase_43 AC 41 ms
4,744 KB
testcase_44 AC 40 ms
4,600 KB
testcase_45 AC 40 ms
4,640 KB
testcase_46 AC 40 ms
4,696 KB
testcase_47 AC 41 ms
4,584 KB
testcase_48 AC 41 ms
4,584 KB
testcase_49 AC 41 ms
4,652 KB
testcase_50 AC 42 ms
4,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  llvec a(N);
  rep(i, N){
    cin >> a[i];
  }
  sort(ALL(a));
  ll ans = 0;
  rep(i, N){
    if(a[i]==1){
      ll ind = upper_bound(ALL(a), 2) - lower_bound(ALL(a), 2);//2の数
      ll ind2 = a.end() - lower_bound(ALL(a), 3);//3以上の数
      ll ind3 = upper_bound(ALL(a), 1) - a.begin();//1の数
      ans += 3*ind + ind2*2 + (ind3-i-1)*2;
    }else{
      ans += 1*(N-i-1);
    }
  }
  cout << ans << endl;
}
0