結果

問題 No.1268 Fruit Rush 2
ユーザー MisterMister
提出日時 2020-10-23 22:14:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 705 bytes
コンパイル時間 715 ms
コンパイル使用メモリ 80,404 KB
実行使用メモリ 6,340 KB
最終ジャッジ日時 2023-09-28 16:02:54
合計ジャッジ時間 3,362 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 31 ms
5,368 KB
testcase_17 AC 27 ms
5,284 KB
testcase_18 AC 29 ms
5,220 KB
testcase_19 AC 29 ms
5,236 KB
testcase_20 AC 28 ms
5,120 KB
testcase_21 AC 27 ms
5,228 KB
testcase_22 AC 31 ms
5,436 KB
testcase_23 AC 31 ms
5,432 KB
testcase_24 AC 29 ms
5,164 KB
testcase_25 AC 26 ms
5,224 KB
testcase_26 AC 46 ms
6,280 KB
testcase_27 AC 45 ms
6,272 KB
testcase_28 AC 46 ms
6,300 KB
testcase_29 AC 46 ms
6,224 KB
testcase_30 AC 46 ms
6,172 KB
testcase_31 AC 39 ms
6,336 KB
testcase_32 AC 40 ms
6,340 KB
testcase_33 AC 43 ms
6,176 KB
testcase_34 AC 25 ms
6,272 KB
testcase_35 AC 44 ms
6,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    std::vector<lint> xs(n);
    for (auto& x : xs) std::cin >> x;
    std::sort(xs.begin(), xs.end());

    std::vector<lint> lens(n, 1);
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 1; j <= 2 && i + j < n; ++j) {
            if (xs[i + j] == xs[i] + 2) lens[i] = lens[i + j] + 1;
        }
    }

    lint ans = n;
    for (int i = 0; i + 1 < n; ++i) {
        if (xs[i + 1] == xs[i] + 1) ans += lens[i + 1];
    }
    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}
0