結果
| 問題 |
No.1268 Fruit Rush 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-23 22:14:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 45 ms / 2,000 ms |
| コード長 | 705 bytes |
| コンパイル時間 | 817 ms |
| コンパイル使用メモリ | 78,968 KB |
| 最終ジャッジ日時 | 2025-01-15 13:13:29 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
using lint = long long;
void solve() {
int n;
std::cin >> n;
std::vector<lint> xs(n);
for (auto& x : xs) std::cin >> x;
std::sort(xs.begin(), xs.end());
std::vector<lint> lens(n, 1);
for (int i = n - 1; i >= 0; --i) {
for (int j = 1; j <= 2 && i + j < n; ++j) {
if (xs[i + j] == xs[i] + 2) lens[i] = lens[i + j] + 1;
}
}
lint ans = n;
for (int i = 0; i + 1 < n; ++i) {
if (xs[i + 1] == xs[i] + 1) ans += lens[i + 1];
}
std::cout << ans << "\n";
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}