結果

問題 No.1268 Fruit Rush 2
ユーザー hanyuhanyu
提出日時 2020-09-19 23:54:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 1,434 bytes
コンパイル時間 2,064 ms
コンパイル使用メモリ 178,360 KB
実行使用メモリ 15,880 KB
最終ジャッジ日時 2023-09-06 03:10:19
合計ジャッジ時間 8,508 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 116 ms
12,492 KB
testcase_17 AC 96 ms
11,228 KB
testcase_18 AC 107 ms
11,648 KB
testcase_19 AC 108 ms
11,756 KB
testcase_20 AC 102 ms
11,344 KB
testcase_21 AC 102 ms
11,332 KB
testcase_22 AC 122 ms
12,888 KB
testcase_23 AC 121 ms
12,808 KB
testcase_24 AC 104 ms
11,740 KB
testcase_25 AC 102 ms
11,332 KB
testcase_26 AC 184 ms
15,844 KB
testcase_27 AC 179 ms
15,848 KB
testcase_28 AC 186 ms
15,708 KB
testcase_29 AC 173 ms
15,704 KB
testcase_30 AC 167 ms
15,880 KB
testcase_31 AC 154 ms
15,752 KB
testcase_32 AC 173 ms
15,760 KB
testcase_33 AC 111 ms
15,800 KB
testcase_34 AC 89 ms
15,732 KB
testcase_35 AC 106 ms
15,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  assert(1 <= n && n <= 2e5);
  
  vector<ll> odd, even;
  set<int> odd_set, even_set;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    assert(1 <= a && a <= 1e18);
    if (a % 2 == 1) {
      odd.emplace_back(a);
      odd_set.insert(a);
    }
    else {
      even.emplace_back(a);
      even_set.insert(a);
    }
  }
  
  assert(odd_set.size() + even_set.size() == n);
  
  sort(odd.begin(), odd.end());
  sort(even.begin(), even.end());
  
  // sentinel
  odd.emplace_back(2e18 - 1);
  even.emplace_back(2e18);
  
  vector<ll> odd_acc(odd.size(), 1), even_acc(even.size(), 1);
  for (int i = odd_acc.size() - 2; i >= 0; i--) {
    if (odd.at(i) == odd.at(i + 1) - 2) odd_acc.at(i) += odd_acc.at(i + 1);
  }
  for (int i = even_acc.size() - 2; i >= 0; i--) {
    if (even.at(i) == even.at(i + 1) - 2) even_acc.at(i) += even_acc.at(i + 1);
  }
  
  ll ans = n;
  int even_it = 0;
  for (int i = 0; i < odd.size() - 1; i++) {
    while (even.at(even_it) <= odd.at(i)) even_it++;
    if (even.at(even_it) == odd.at(i) + 1) ans += even_acc.at(even_it);
  }
  int odd_it = 0;
  for (int i = 0; i < even.size() - 1; i++) {
    while (odd.at(odd_it) <= even.at(i)) odd_it++;
    if (odd.at(odd_it) == even.at(i) + 1) ans += odd_acc.at(odd_it);
  }
  
  cout << ans << '\n';
}
0