結果

問題 No.1470 Mex Sum
ユーザー JanglishJanglish
提出日時 2021-04-16 16:02:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,566 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 84,324 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 13:16:14
合計ジャッジ時間 4,256 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 6 ms
4,380 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 38 ms
4,380 KB
testcase_13 AC 37 ms
4,376 KB
testcase_14 AC 37 ms
4,380 KB
testcase_15 AC 38 ms
4,376 KB
testcase_16 AC 37 ms
4,380 KB
testcase_17 AC 36 ms
4,376 KB
testcase_18 AC 36 ms
4,376 KB
testcase_19 AC 37 ms
4,380 KB
testcase_20 AC 37 ms
4,376 KB
testcase_21 AC 38 ms
4,376 KB
testcase_22 AC 38 ms
4,380 KB
testcase_23 AC 39 ms
4,376 KB
testcase_24 AC 38 ms
4,380 KB
testcase_25 AC 39 ms
4,380 KB
testcase_26 AC 38 ms
4,376 KB
testcase_27 AC 38 ms
4,380 KB
testcase_28 AC 39 ms
4,380 KB
testcase_29 AC 39 ms
4,376 KB
testcase_30 AC 38 ms
4,376 KB
testcase_31 AC 39 ms
4,380 KB
testcase_32 AC 38 ms
4,380 KB
testcase_33 AC 38 ms
4,376 KB
testcase_34 AC 38 ms
4,380 KB
testcase_35 AC 38 ms
4,376 KB
testcase_36 AC 38 ms
4,380 KB
testcase_37 AC 28 ms
4,376 KB
testcase_38 AC 29 ms
4,380 KB
testcase_39 AC 29 ms
4,376 KB
testcase_40 AC 29 ms
4,376 KB
testcase_41 AC 29 ms
4,380 KB
testcase_42 AC 29 ms
4,376 KB
testcase_43 AC 28 ms
4,376 KB
testcase_44 AC 29 ms
4,380 KB
testcase_45 AC 29 ms
4,376 KB
testcase_46 AC 29 ms
4,380 KB
testcase_47 AC 28 ms
4,380 KB
testcase_48 AC 29 ms
4,376 KB
testcase_49 AC 29 ms
4,376 KB
testcase_50 AC 29 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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