結果

問題 No.1268 Fruit Rush 2
ユーザー hanyuhanyu
提出日時 2020-09-20 00:04:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,518 bytes
コンパイル時間 1,776 ms
コンパイル使用メモリ 176,920 KB
実行使用メモリ 18,676 KB
最終ジャッジ日時 2023-09-06 03:22:22
合計ジャッジ時間 8,259 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,752 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 95 ms
11,356 KB
testcase_17 AC 75 ms
10,796 KB
testcase_18 AC 82 ms
10,676 KB
testcase_19 AC 83 ms
10,824 KB
testcase_20 AC 79 ms
10,792 KB
testcase_21 AC 73 ms
10,932 KB
testcase_22 AC 94 ms
11,472 KB
testcase_23 AC 93 ms
11,588 KB
testcase_24 AC 83 ms
10,660 KB
testcase_25 AC 76 ms
10,868 KB
testcase_26 AC 146 ms
14,000 KB
testcase_27 AC 145 ms
14,192 KB
testcase_28 AC 136 ms
14,236 KB
testcase_29 AC 149 ms
14,060 KB
testcase_30 AC 137 ms
14,164 KB
testcase_31 TLE -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// O(N^2)解法
#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);
  
  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) {
      ll keep = 1, it2 = even_it;
      while (true) {
        if (even.at(it2) + 2 == even.at(it2 + 1)) {
          keep++;
          it2++;
        }
        else {
          break;
        }
      }
      ans += keep;
    }
  }
  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) {
      ll keep = 1, it2 = odd_it;
      while (true) {
        if (odd.at(it2) + 2 == odd.at(it2 + 1)) {
          keep++;
          it2++;
        }
        else {
          break;
        }
      }
      ans += keep;
    }
  }
  
  cout << ans << '\n';
}
0