結果

問題 No.1470 Mex Sum
ユーザー Janglish
提出日時 2021-04-16 16:02:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,566 bytes
コンパイル時間 721 ms
コンパイル使用メモリ 86,136 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-02 16:25:32
合計ジャッジ時間 4,804 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define VEC(type, name, size)

#define fi first
#define se second
#define all(c) begin(c), end(c)
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
void YES(bool t = 1) { cout << YESNO[t] << endl; }
void Yes(bool t = 1) { cout << YesNo[t] << endl; }
void yes(bool t = 1) { cout << yesno[t] << endl; }

int main() {
    int N; cin >> N;
    vi A(N);
    rep(i, N) cin >> A[i];

    ll x = count(all(A), 1);
    ll y = count(all(A), 2);
    ll z = N - x - y;

    ll ans = 0;
    ans += y * (y - 1) / 2 + y * z + z * (z - 1) / 2; // mex = 1 (2, 2), (2, 3), (3, 2), (3, 3)
    ans += 2 * (x * (x - 1) / 2 + x * z); // mex = 2 (1, 1), (1, 3), (3, 1)
    ans += 3 * x * y; // mex = 3 (1, 2), (2, 1)

    cout << ans << endl;
    return 0;
}
0