結果

問題 No.1268 Fruit Rush 2
ユーザー MisterMister
提出日時 2020-10-23 23:40:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 697 ms / 2,000 ms
コード長 788 bytes
コンパイル時間 870 ms
コンパイル使用メモリ 89,600 KB
実行使用メモリ 56,712 KB
最終ジャッジ日時 2023-09-28 18:57:30
合計ジャッジ時間 12,561 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 409 ms
31,300 KB
testcase_17 AC 352 ms
29,116 KB
testcase_18 AC 385 ms
29,716 KB
testcase_19 AC 378 ms
29,692 KB
testcase_20 AC 368 ms
29,356 KB
testcase_21 AC 354 ms
29,024 KB
testcase_22 AC 406 ms
31,232 KB
testcase_23 AC 414 ms
31,476 KB
testcase_24 AC 369 ms
29,564 KB
testcase_25 AC 364 ms
29,392 KB
testcase_26 AC 683 ms
56,568 KB
testcase_27 AC 686 ms
56,512 KB
testcase_28 AC 683 ms
56,708 KB
testcase_29 AC 695 ms
56,712 KB
testcase_30 AC 697 ms
56,560 KB
testcase_31 AC 521 ms
34,636 KB
testcase_32 AC 523 ms
34,648 KB
testcase_33 AC 402 ms
34,820 KB
testcase_34 AC 538 ms
56,500 KB
testcase_35 AC 556 ms
56,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <map>

using lint = long long;

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

    std::set<lint> xs, ks;
    while (n--) {
        lint x;
        std::cin >> x;

        xs.insert(x);
        ks.insert(x);
        ks.insert(x + 1);
    }

    lint ans = 0;
    std::map<lint, lint> dp;  // sumがF_kになる選び方の総数

    for (auto k : ks) {
        auto& pat = dp[k];
        pat = 0;

        // F_k単体
        if (xs.count(k)) ++pat;

        // F_{k-1}を使いF_{k-2}に帰着
        if (xs.count(k - 1) &&
            dp.count(k - 2)) pat += dp[k - 2];

        ans += pat;
    }

    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}
0