結果

問題 No.1268 Fruit Rush 2
ユーザー merom686
提出日時 2020-10-23 23:38:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 928 bytes
コンパイル時間 988 ms
コンパイル使用メモリ 96,612 KB
最終ジャッジ日時 2025-01-15 14:12:15
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    ll r = 0;
    for (int h = 0; h < 2; h++) {
        int k = 0;
        ll p = -1;
        for (int i = n - 1; i >= 0; i--) {
            if (a[i] % 2 == h) {
                if (a[i] == p - 2) {
                    k++;
                } else {
                    k = 1;
                }
                p = a[i];
            } else {
                if (a[i] == p - 1) {
                    r += k + 1;
                } else {
                    r += 1;
                }
            }
        }
    }

    cout << r << endl;

    return 0;
}
0