結果

問題 No.1268 Fruit Rush 2
ユーザー stoqstoq
提出日時 2020-09-18 08:09:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 880 ms
コンパイル使用メモリ 83,296 KB
実行使用メモリ 12,128 KB
最終ジャッジ日時 2023-09-04 08:29:47
合計ジャッジ時間 5,021 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 59 ms
5,428 KB
testcase_17 AC 51 ms
5,220 KB
testcase_18 AC 54 ms
5,200 KB
testcase_19 AC 53 ms
5,260 KB
testcase_20 AC 52 ms
5,192 KB
testcase_21 AC 51 ms
5,104 KB
testcase_22 AC 59 ms
5,528 KB
testcase_23 AC 59 ms
5,428 KB
testcase_24 AC 53 ms
5,096 KB
testcase_25 AC 52 ms
5,144 KB
testcase_26 AC 108 ms
6,488 KB
testcase_27 AC 108 ms
6,204 KB
testcase_28 AC 108 ms
7,728 KB
testcase_29 AC 109 ms
6,152 KB
testcase_30 AC 108 ms
6,956 KB
testcase_31 AC 77 ms
8,264 KB
testcase_32 AC 78 ms
9,368 KB
testcase_33 AC 137 ms
8,084 KB
testcase_34 AC 70 ms
12,128 KB
testcase_35 AC 140 ms
11,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
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;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    a[i]--;
  }
  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