結果

問題 No.1268 Fruit Rush 2
ユーザー Fu_LFu_L
提出日時 2024-03-02 15:21:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,451 bytes
コンパイル時間 2,413 ms
コンパイル使用メモリ 209,332 KB
実行使用メモリ 8,308 KB
最終ジャッジ日時 2024-03-02 15:21:13
合計ジャッジ時間 5,302 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 51 ms
7,056 KB
testcase_17 AC 45 ms
6,676 KB
testcase_18 AC 47 ms
6,696 KB
testcase_19 AC 46 ms
6,688 KB
testcase_20 AC 45 ms
6,756 KB
testcase_21 AC 44 ms
6,676 KB
testcase_22 AC 52 ms
7,152 KB
testcase_23 AC 51 ms
7,128 KB
testcase_24 AC 46 ms
6,752 KB
testcase_25 AC 44 ms
6,676 KB
testcase_26 AC 62 ms
8,200 KB
testcase_27 AC 63 ms
8,308 KB
testcase_28 AC 62 ms
8,284 KB
testcase_29 AC 63 ms
8,196 KB
testcase_30 AC 62 ms
8,288 KB
testcase_31 AC 67 ms
8,284 KB
testcase_32 AC 67 ms
8,200 KB
testcase_33 AC 55 ms
8,284 KB
testcase_34 AC 29 ms
8,192 KB
testcase_35 AC 48 ms
8,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, a, b) for(ll i = a; i < b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)
constexpr ll inf = 4e18;
struct SetupIO {
    SetupIO() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout << fixed << setprecision(30);
    }
} setup_io;
int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n), even, odd;
    rep(i, 0, n) {
        cin >> a[i];
        if(a[i] % 2 == 0) {
            even.push_back(a[i]);
        } else {
            odd.push_back(a[i]);
        }
    }
    sort(a.begin(), a.end());
    sort(even.begin(), even.end());
    sort(odd.begin(), odd.end());
    vector<ll> cnt_even(even.size(), 1), cnt_odd(odd.size(), 1);
    rrep(i, (int)even.size() - 2, 0) {
        if(even[i + 1] - even[i] == 2) {
            cnt_even[i] = cnt_even[i + 1] + 1;
        }
    }
    rrep(i, (int)odd.size() - 2, 0) {
        if(odd[i + 1] - odd[i] == 2) {
            cnt_odd[i] = cnt_odd[i + 1] + 1;
        }
    }
    ll ans = n;
    rep(i, 0, n - 1) {
        if(a[i + 1] - a[i] != 1) continue;
        if(a[i] % 2 == 0) {
            ll idx = lower_bound(odd.begin(), odd.end(), a[i + 1]) - odd.begin();
            ans += cnt_odd[idx];
        } else {
            ll idx = lower_bound(even.begin(), even.end(), a[i + 1]) - even.begin();
            ans += cnt_even[idx];
        }
    }
    cout << ans << '\n';
}
0