結果
| 問題 |
No.1268 Fruit Rush 2
|
| ユーザー |
stoq
|
| 提出日時 | 2020-09-18 09:59:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 200 ms / 2,000 ms |
| コード長 | 1,048 bytes |
| コンパイル時間 | 1,909 ms |
| コンパイル使用メモリ | 206,996 KB |
| 最終ジャッジ日時 | 2025-01-14 16:05:49 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
#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;
}
stoq