結果

問題 No.1268 Fruit Rush 2
ユーザー tnakao0123tnakao0123
提出日時 2020-10-26 11:28:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,323 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 93,756 KB
実行使用メモリ 6,164 KB
最終ジャッジ日時 2023-09-29 02:31:37
合計ジャッジ時間 3,432 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 46 ms
5,800 KB
testcase_27 AC 47 ms
5,880 KB
testcase_28 AC 46 ms
5,736 KB
testcase_29 AC 46 ms
5,936 KB
testcase_30 AC 46 ms
5,872 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 27 ms
5,824 KB
testcase_35 AC 43 ms
5,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1268.cc:  No.1268 Fruit Rush 2 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

/* global variables */

ll as[MAX_N];
int dp[MAX_N];

/* subroutines */

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%lld", as + i);
  sort(as, as + n);

  for (int i = n - 1; i >= 0; i--) {
    dp[i] = 1;
    if (i + 1 < n && as[i + 1] == as[i] + 2) setmax(dp[i], dp[i + 1] + 1);
    if (i + 2 < n && as[i + 2] == as[i] + 2) setmax(dp[i], dp[i + 1] + 1);
  }
  //for (int i = 0; i < n; i++) printf("%d ", dp[i]); putchar('\n');

  ll sum = 0;
  for (int i = 0; i < n; i++) {
    sum++;
    if (i + 1 < n && as[i + 1] == as[i] + 1) {
      sum++;
      if (i + 2 < n && as[i + 2] == as[i] + 3) sum += dp[i + 2];
      if (i + 3 < n && as[i + 3] == as[i] + 3) sum += dp[i + 3];
    }
  }

  printf("%lld\n", sum);
  return 0;
}
0