結果

問題 No.1470 Mex Sum
ユーザー kimiyukikimiyuki
提出日時 2021-04-09 21:32:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,159 bytes
コンパイル時間 4,105 ms
コンパイル使用メモリ 200,024 KB
実行使用メモリ 6,392 KB
最終ジャッジ日時 2023-09-07 10:04:22
合計ジャッジ時間 5,523 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 4 ms
4,384 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 4 ms
4,384 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 3 ms
4,384 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 20 ms
6,256 KB
testcase_13 AC 19 ms
6,232 KB
testcase_14 AC 19 ms
6,124 KB
testcase_15 AC 20 ms
6,300 KB
testcase_16 AC 19 ms
5,996 KB
testcase_17 AC 19 ms
5,880 KB
testcase_18 AC 19 ms
5,912 KB
testcase_19 AC 20 ms
5,852 KB
testcase_20 AC 19 ms
5,944 KB
testcase_21 AC 21 ms
6,124 KB
testcase_22 AC 20 ms
6,228 KB
testcase_23 AC 21 ms
6,200 KB
testcase_24 AC 21 ms
6,232 KB
testcase_25 AC 21 ms
6,120 KB
testcase_26 AC 20 ms
6,124 KB
testcase_27 AC 21 ms
6,144 KB
testcase_28 AC 20 ms
6,252 KB
testcase_29 AC 20 ms
6,124 KB
testcase_30 AC 20 ms
6,144 KB
testcase_31 AC 21 ms
6,168 KB
testcase_32 AC 20 ms
6,128 KB
testcase_33 AC 20 ms
6,152 KB
testcase_34 AC 20 ms
6,392 KB
testcase_35 AC 21 ms
6,152 KB
testcase_36 AC 20 ms
6,232 KB
testcase_37 AC 16 ms
6,224 KB
testcase_38 AC 16 ms
6,156 KB
testcase_39 AC 16 ms
6,388 KB
testcase_40 AC 18 ms
6,152 KB
testcase_41 AC 18 ms
6,232 KB
testcase_42 AC 18 ms
6,176 KB
testcase_43 AC 18 ms
6,112 KB
testcase_44 AC 17 ms
6,236 KB
testcase_45 AC 17 ms
6,148 KB
testcase_46 AC 17 ms
6,124 KB
testcase_47 AC 18 ms
6,168 KB
testcase_48 AC 17 ms
6,232 KB
testcase_49 AC 17 ms
6,224 KB
testcase_50 AC 17 ms
6,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

int mex(int a, int b) {
    if (a != 1 and b != 1) return 1;
    if (a != 2 and b != 2) return 2;
    if (a != 3 and b != 3) return 3;
    if (a != 4 and b != 4) return 4;
    assert (false);
}

int64_t solve(int n, vector<int64_t> a) {
    int64_t ans = 0;
    array<int, 4> k = {};
    REP (i, n) {
        int b = min<int64_t>(3, a[i]);
        REP3 (c, 1, 4) {
            ans += k[c] * mex(b, c);
        }
        k[b] += 1;
    }
    return ans;
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int N;
    cin >> N;
    vector<int64_t> A(N);
    REP (i, N) { cin >> A[i]; }
    auto ans = solve(N, A);
    cout << ans << endl;
    return 0;
}
0