結果

問題 No.1268 Fruit Rush 2
ユーザー こまるこまる
提出日時 2020-11-11 18:39:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 3,329 bytes
コンパイル時間 2,214 ms
コンパイル使用メモリ 205,088 KB
実行使用メモリ 5,680 KB
最終ジャッジ日時 2023-09-30 00:47:56
合計ジャッジ時間 4,429 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 29 ms
4,852 KB
testcase_17 AC 26 ms
4,640 KB
testcase_18 AC 27 ms
4,636 KB
testcase_19 AC 26 ms
4,704 KB
testcase_20 AC 27 ms
4,636 KB
testcase_21 AC 26 ms
4,588 KB
testcase_22 AC 30 ms
4,848 KB
testcase_23 AC 29 ms
5,144 KB
testcase_24 AC 27 ms
4,888 KB
testcase_25 AC 26 ms
4,624 KB
testcase_26 AC 43 ms
5,496 KB
testcase_27 AC 43 ms
5,432 KB
testcase_28 AC 42 ms
5,376 KB
testcase_29 AC 43 ms
5,376 KB
testcase_30 AC 42 ms
5,496 KB
testcase_31 AC 38 ms
5,620 KB
testcase_32 AC 38 ms
5,416 KB
testcase_33 AC 39 ms
5,496 KB
testcase_34 AC 23 ms
5,376 KB
testcase_35 AC 39 ms
5,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using i8   = int8_t; using i16  = int16_t; using i32  = int32_t; using i64  = int64_t; using i128 = __int128_t; using u8   = uint8_t; using u16  = uint16_t; using u32  = uint32_t; using u64  = uint64_t; using u128 = __uint128_t; using vi32 = vector<i32>; using vi64 = vector<i64>; using vu32 = vector<u32>; using vu64 = vector<u64>; using pi32 = pair<i32, i32>; using pi64 = pair<i64, i64>; using pu32 = pair<u32, u32>; using pu64 = pair<u64, u64>; using vpi32 = vector<pi32>; using vpi64 = vector<pi64>; using vpu32 = vector<pu32>; using vpu64 = vector<pu64>;
using f32 = float;
using f64 = double;
const char alphabetl[26] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
const char alphabetu[26] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
const i32 dx[4] = { 1, 0, -1, 0 };
const i32 dy[4] = { 0, 1, 0, -1 };
const double pi     = 3.141592653589793238462643383279502884197169;
const double napier = 2.718281828459045235360287471352662497757247;
static const double EPS = 1e-8;
static const i64 INF64 = 1e18;
static const i32 INF32 = (1 << 30) - 1;
static const i64 MOD = (i64) 1e9 + 7;
const int NM = 100100;

#define cauto const auto&
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define itn int

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))

#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)

#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=0; i<=(int)(n); i++)
#define rrep(i,n) for(int i=(n-1); i>=0; i--)
#define rreps(i,n) for(int i=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define FOREQ(i,a,b) for(int i=a; i<=(int)(b); i++)
#define RFOR(i,a,b) for(int i=a; i>(int)(b); i--)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)

#define ALL(x) (x).begin(),(x).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()

#define PRINT(n) cout << n << "\n";
#define PRINT2(n, m) cout << n << " " << m << " "<< "\n";

#define IN(a, x, b) (a<=x && x<b)
#define pb push_back
#define fst first
#define snd second

template<class T1, class T2>
bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2>
bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

void Main();
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
    Main();
    return 0;
}

void Main(){
    // your code here!
    int N;
    cin >> N;
    vi64 A(N);
    rep(i,N) cin >> A[i];
    sort(ALL(A));
    vi32 dp(N+1,0);
    for(int i=N; i>=0; i--){
        if(i+1<N && A[i]+2 == A[i+1]) dp[i] = dp[i+1]+1;
        if(i+2<N && A[i]+2 == A[i+2]) dp[i] = dp[i+2]+1;
    }
    i64 ans=N;
    for(int i=0; i+1<N;i++) {
        if(A[i]+1!=A[i+1]) continue;
        ans+=dp[i+1]+1;
    }
    cout<<ans<<endl;
}
0