結果

問題 No.1470 Mex Sum
ユーザー TomorrowNextTomorrowNext
提出日時 2021-04-09 21:51:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,197 bytes
コンパイル時間 1,557 ms
コンパイル使用メモリ 167,528 KB
実行使用メモリ 11,216 KB
最終ジャッジ日時 2023-09-07 10:56:41
合計ジャッジ時間 5,675 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 6 ms
4,376 KB
testcase_03 AC 6 ms
4,376 KB
testcase_04 AC 7 ms
4,376 KB
testcase_05 AC 6 ms
4,376 KB
testcase_06 AC 7 ms
4,376 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 5 ms
4,384 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 47 ms
10,788 KB
testcase_13 AC 46 ms
10,992 KB
testcase_14 AC 47 ms
10,632 KB
testcase_15 AC 47 ms
10,788 KB
testcase_16 AC 46 ms
10,416 KB
testcase_17 AC 46 ms
10,548 KB
testcase_18 AC 46 ms
10,420 KB
testcase_19 AC 47 ms
10,372 KB
testcase_20 AC 46 ms
10,436 KB
testcase_21 AC 48 ms
10,672 KB
testcase_22 AC 48 ms
11,216 KB
testcase_23 AC 48 ms
10,944 KB
testcase_24 AC 48 ms
10,888 KB
testcase_25 AC 48 ms
10,936 KB
testcase_26 AC 49 ms
10,900 KB
testcase_27 AC 48 ms
10,896 KB
testcase_28 AC 48 ms
10,936 KB
testcase_29 AC 47 ms
10,896 KB
testcase_30 AC 48 ms
11,072 KB
testcase_31 AC 48 ms
10,944 KB
testcase_32 AC 48 ms
11,068 KB
testcase_33 AC 48 ms
11,068 KB
testcase_34 AC 48 ms
10,896 KB
testcase_35 AC 48 ms
11,068 KB
testcase_36 AC 48 ms
11,060 KB
testcase_37 AC 37 ms
10,956 KB
testcase_38 AC 36 ms
10,996 KB
testcase_39 AC 36 ms
10,896 KB
testcase_40 AC 38 ms
10,936 KB
testcase_41 AC 38 ms
10,952 KB
testcase_42 AC 39 ms
11,060 KB
testcase_43 AC 39 ms
10,944 KB
testcase_44 AC 39 ms
10,960 KB
testcase_45 AC 39 ms
10,888 KB
testcase_46 AC 39 ms
11,064 KB
testcase_47 AC 38 ms
11,000 KB
testcase_48 AC 38 ms
10,892 KB
testcase_49 AC 38 ms
10,896 KB
testcase_50 AC 38 ms
11,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;
using ll = long long;

void Main() {
    ll N;
    cin >> N;
    vector<ll> A(N, 0);
    for (ll i = 0; i < N; ++i) {
        cin >> A[i];
    }

    vector<ll> cnt1(N + 1, 0), cnt2(N + 1, 0);
    cnt1[0] = 0;
    cnt2[0] = 0;
    for (ll i = 1; i < N + 1; ++i) {
        cnt1[i] = cnt1[i - 1] + (A[i - 1] == 1 ? 1 : 0);
        cnt2[i] = cnt2[i - 1] + (A[i - 1] == 2 ? 1 : 0);
    }
    vector<ll> num1From(N, 0), num2From(N, 0);
    for (ll i = 0; i < N; ++i) {
        num1From[i] = cnt1.back() - cnt1[i];
        num2From[i] = cnt2.back() - cnt2[i];
    }
    ll ans = 0LL;
    for (ll i = 0; i < N - 1; ++i) {
        if (A[i] == 1) {
            ll n = num2From[i + 1];
            ans += n * 3;
            ans += (N - i - 1 - n) * 2;
        }
        else if (A[i] == 2) {
            ll n = num1From[i + 1];
            ans += n * 3;
            ans += (N - i - 1 - n) * 1;
        }
        else {
            ll n = num1From[i + 1];
            ans += n * 2;
            ans += (N - i - 1 - n) * 1;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}
0