結果

問題 No.1268 Fruit Rush 2
ユーザー hanyuhanyu
提出日時 2020-05-31 15:09:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 750 bytes
コンパイル時間 1,537 ms
コンパイル使用メモリ 172,248 KB
実行使用メモリ 14,660 KB
最終ジャッジ日時 2023-09-04 08:32:58
合計ジャッジ時間 5,598 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,568 KB
testcase_01 AC 3 ms
4,624 KB
testcase_02 AC 3 ms
4,564 KB
testcase_03 AC 3 ms
4,572 KB
testcase_04 AC 4 ms
4,508 KB
testcase_05 AC 3 ms
4,560 KB
testcase_06 AC 4 ms
4,608 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 3 ms
4,800 KB
testcase_10 AC 3 ms
4,628 KB
testcase_11 AC 3 ms
4,528 KB
testcase_12 RE -
testcase_13 AC 3 ms
4,624 KB
testcase_14 AC 3 ms
4,704 KB
testcase_15 RE -
testcase_16 AC 84 ms
12,280 KB
testcase_17 AC 70 ms
11,176 KB
testcase_18 AC 78 ms
11,648 KB
testcase_19 AC 75 ms
11,472 KB
testcase_20 AC 72 ms
11,568 KB
testcase_21 AC 74 ms
11,564 KB
testcase_22 AC 82 ms
12,276 KB
testcase_23 AC 87 ms
12,224 KB
testcase_24 AC 78 ms
11,556 KB
testcase_25 AC 70 ms
11,428 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 127 ms
14,660 KB
testcase_32 AC 134 ms
14,656 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
権限があれば一括ダウンロードができます

ソースコード

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<int> a(n);
  set<int> s;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    assert(1 <= a.at(i) && a.at(i) <= 2e5);
    s.insert(a.at(i));
  }
  
  assert(s.size() == n);
  
  ll ans = n; // 1個だけ選ぶとき
  vector<ll> x(2e5, 0); // 1個飛ばしでどれだけ連続しているか
  for (int i = 0; i < n; i++) x.at(a.at(i) - 1)++;
  for (int i = 2e5 - 3; i >= 0; i--) {
    if (x.at(i) > 0) x.at(i) += x.at(i + 2);
  }
  for (int i = 1; i < 2e5; i++) {
    if (x.at(i - 1) > 0 && x.at(i) > 0) ans += x.at(i);
  }
  
  cout << ans << '\n';
}
0