結果

問題 No.1268 Fruit Rush 2
ユーザー stoqstoq
提出日時 2020-09-18 09:59:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 1,048 bytes
コンパイル時間 2,252 ms
コンパイル使用メモリ 210,960 KB
実行使用メモリ 20,572 KB
最終ジャッジ日時 2023-09-04 08:36:55
合計ジャッジ時間 7,271 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,384 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 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 134 ms
12,668 KB
testcase_17 AC 107 ms
11,176 KB
testcase_18 AC 118 ms
11,720 KB
testcase_19 AC 118 ms
11,748 KB
testcase_20 AC 111 ms
11,520 KB
testcase_21 AC 109 ms
11,136 KB
testcase_22 AC 133 ms
12,556 KB
testcase_23 AC 135 ms
12,600 KB
testcase_24 AC 113 ms
12,028 KB
testcase_25 AC 110 ms
11,396 KB
testcase_26 AC 222 ms
15,560 KB
testcase_27 AC 218 ms
15,508 KB
testcase_28 AC 220 ms
15,592 KB
testcase_29 AC 225 ms
15,424 KB
testcase_30 AC 227 ms
15,724 KB
testcase_31 AC 192 ms
19,056 KB
testcase_32 AC 186 ms
17,476 KB
testcase_33 AC 196 ms
17,624 KB
testcase_34 AC 128 ms
20,572 KB
testcase_35 AC 199 ms
20,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll calc(const vector<ll> &a)
{
  int n = a.size();
  int maxA = a.back();
  vector<ll> dp(maxA + 2, 0);
  vector<bool> exist(maxA + 2, 0);
  for (int i = 0; i < n; i++)
    exist[a[i]] = true;
  for (int i = 0; i < maxA + 2; i++)
  {
    dp[i] += exist[i];
    if (i >= 2 and exist[i - 1])
      dp[i] += dp[i - 2];
  }
  ll sum = 0;
  for (int i = 0; i < maxA + 2; i++)
    sum += dp[i];
  return sum;
}

int main()
{
  int n;
  assert(cin >> n);
  assert(1 <= n and n <= 200000);
  vector<ll> a(n);
  set<ll> st;
  for (int i = 0; i < n; i++)
  {
    assert(cin >> a[i]);
    st.insert(a[i]);
    assert(1 <= a[i] and a[i] <= 1e18);
    a[i]--;
  }
  assert(st.size() == n);
  sort(begin(a), end(a));
  a.push_back(2e18);

  ll ans = 0, minus = a[0];
  vector<ll> v;
  for (int i = 0; i < n; i++)
  {
    v.push_back(a[i] - minus);
    if (a[i + 1] - a[i] >= 3)
    {
      ans += calc(v);
      v.clear();
      minus = a[i + 1];
    }
  }
  cout << ans << "\n";
  return 0;
}
0