結果

問題 No.1268 Fruit Rush 2
ユーザー tonyu0
提出日時 2020-10-24 08:44:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 406 ms / 2,000 ms
コード長 672 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 125,128 KB
最終ジャッジ日時 2025-01-15 14:52:30
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (n); ++i)
#define rrep(i, j, n) for (int i = (n)-1; j <= i; --i)

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  sort(a.begin(), a.end());
  // 重複は一個前
  unordered_map<ll, ll> dp;
  rep(i, 0, n) {
    ++dp[a[i]];
    dp[a[i] + 1] += dp[a[i] - 1];
  }
  ll ans = 0;
  for (auto itr : dp) ans += itr.second;
  cout << ans << endl;
  return 0;
}
0