結果

問題 No.1268 Fruit Rush 2
コンテスト
ユーザー polylogK
提出日時 2020-10-23 23:12:49
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,175 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,458 ms
コンパイル使用メモリ 219,040 KB
実行使用メモリ 8,456 KB
最終ジャッジ日時 2026-06-14 18:08:02
合計ジャッジ時間 3,308 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<i64> a(n);
	for(auto& v: a) scanf("%lld", &v);
	sort(begin(a), end(a));

	std::vector<std::pair<i64, i64>> A, B;
	for(auto v: a) {
		if(v & 1) {
			if(A.empty() or A.back().second + 2 != v) A.push_back({v, v});
			else A.back().second += 2;
		} else {
			if(B.empty() or B.back().second + 2 != v) B.push_back({v, v});
			else B.back().second += 2;
		}
	}

	i64 ans = n;
	int x = 0, y = 0;
	for(int i = 0; i < n; i++) {
		if(i + 1 >= n or a[i] + 1 != a[i + 1]) continue;
		while(x < A.size() and A[x].second < a[i]) x++;
		while(y < B.size() and B[y].second < a[i]) y++;

		if(a[i] & 1) {
			ans += (B[y].second - a[i + 1]) / 2 + 1;
		} else {
			ans += (A[x].second - a[i + 1]) / 2 + 1;
		}
	}
	printf("%lld\n", ans);
	return 0;
}
0