結果

問題 No.1268 Fruit Rush 2
ユーザー ocvret_
提出日時 2020-10-24 11:47:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 808 bytes
コンパイル時間 1,607 ms
コンパイル使用メモリ 174,592 KB
実行使用メモリ 22,912 KB
最終ジャッジ日時 2024-07-21 15:08:32
合計ジャッジ時間 4,638 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

vector<ll> dp(200100,-1);
ll dfs(vector<ll> &v,int pos){
  if(pos >= v.size())return 0;
  if(dp[pos] != -1)return dp[pos];
  ll res = 0;
  for(int i = 1;i <= 2;i++){
    if(pos+i >= v.size())break;
    if(v[pos+i]-v[pos] == 2)res += dfs(v,pos+i);
  }
  return dp[pos] = res+1;
}

int main(){
  
  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i,n)cin >> v[i];
  sort(ALL(v));
  vector<int> l(n);
  rep(i,n)dfs(v,i);
  ll res = n;
  for(int i = 1;i < n;i++)if(v[i]-v[i-1] == 1)res += dp[i];
  cout << res << "\n";


  return 0;
}
0