結果

問題 No.1268 Fruit Rush 2
ユーザー sahiyasahiya
提出日時 2020-12-14 16:44:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 1,429 bytes
コンパイル時間 1,786 ms
コンパイル使用メモリ 123,644 KB
実行使用メモリ 29,144 KB
最終ジャッジ日時 2023-10-20 05:05:58
合計ジャッジ時間 6,916 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 55 ms
13,880 KB
testcase_17 AC 51 ms
13,712 KB
testcase_18 AC 53 ms
13,772 KB
testcase_19 AC 52 ms
13,760 KB
testcase_20 AC 52 ms
13,744 KB
testcase_21 AC 51 ms
13,724 KB
testcase_22 AC 54 ms
13,884 KB
testcase_23 AC 56 ms
13,888 KB
testcase_24 AC 53 ms
13,760 KB
testcase_25 AC 52 ms
13,732 KB
testcase_26 AC 260 ms
29,144 KB
testcase_27 AC 264 ms
29,144 KB
testcase_28 AC 274 ms
29,144 KB
testcase_29 AC 266 ms
29,144 KB
testcase_30 AC 241 ms
29,144 KB
testcase_31 AC 65 ms
14,244 KB
testcase_32 AC 66 ms
14,244 KB
testcase_33 AC 67 ms
14,244 KB
testcase_34 AC 73 ms
24,048 KB
testcase_35 AC 90 ms
24,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef bitset<16> BS;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 2E+05;

int N;

ll A[MAX_N + 2];

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

    cin >> N;

    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    sort(A + 1, A + N + 1);
    unordered_map<ll, ll> dp;

    for (int i = 1; i <= N; i++) {
        dp[A[i]]++;
        if (A[i - 1] == A[i] - 1)
            dp[A[i]] += dp[A[i] - 2];
        if (A[i + 1] != A[i] + 1)
            dp[A[i] + 1] += dp[A[i] - 1];
    }

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    ll ans = 0;
    for (auto p : dp) {
        ll res = p.second;
        //cout << "a = " << p.first << ", res = " << res << "\n";
        ans += res;
    }

    cout << ans << "\n";

    return 0;
}
0