結果

問題 No.1268 Fruit Rush 2
ユーザー polylogKpolylogK
提出日時 2020-10-23 23:12:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,175 bytes
コンパイル時間 2,108 ms
コンパイル使用メモリ 207,256 KB
実行使用メモリ 8,172 KB
最終ジャッジ日時 2023-09-28 17:59:18
合計ジャッジ時間 5,466 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 34 ms
5,336 KB
testcase_17 AC 30 ms
5,352 KB
testcase_18 AC 31 ms
5,276 KB
testcase_19 AC 31 ms
5,232 KB
testcase_20 AC 31 ms
5,128 KB
testcase_21 AC 30 ms
5,248 KB
testcase_22 AC 34 ms
5,208 KB
testcase_23 AC 34 ms
5,400 KB
testcase_24 AC 31 ms
5,176 KB
testcase_25 AC 30 ms
5,184 KB
testcase_26 AC 51 ms
8,172 KB
testcase_27 AC 52 ms
8,052 KB
testcase_28 AC 52 ms
7,964 KB
testcase_29 AC 52 ms
7,972 KB
testcase_30 AC 51 ms
8,116 KB
testcase_31 AC 41 ms
4,732 KB
testcase_32 AC 42 ms
4,572 KB
testcase_33 AC 43 ms
4,672 KB
testcase_34 AC 27 ms
4,572 KB
testcase_35 AC 42 ms
4,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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