結果

問題 No.1268 Fruit Rush 2
ユーザー milanis48663220milanis48663220
提出日時 2020-10-23 23:35:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,307 bytes
コンパイル時間 1,555 ms
コンパイル使用メモリ 88,388 KB
実行使用メモリ 10,356 KB
最終ジャッジ日時 2023-09-28 18:50:27
合計ジャッジ時間 3,285 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 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,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 29 ms
4,572 KB
testcase_17 AC 26 ms
4,380 KB
testcase_18 AC 27 ms
4,400 KB
testcase_19 AC 26 ms
4,388 KB
testcase_20 AC 27 ms
4,504 KB
testcase_21 AC 26 ms
4,400 KB
testcase_22 AC 29 ms
4,828 KB
testcase_23 AC 30 ms
4,532 KB
testcase_24 AC 27 ms
4,608 KB
testcase_25 AC 26 ms
4,376 KB
testcase_26 AC 44 ms
4,860 KB
testcase_27 AC 44 ms
5,160 KB
testcase_28 AC 43 ms
4,988 KB
testcase_29 AC 43 ms
4,924 KB
testcase_30 AC 43 ms
4,932 KB
testcase_31 AC 40 ms
6,768 KB
testcase_32 AC 40 ms
6,744 KB
testcase_33 AC 45 ms
6,580 KB
testcase_34 AC 29 ms
10,356 KB
testcase_35 AC 47 ms
9,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int n;
ll a[200000];

void input(){
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
}


void solve(){
    sort(a, a+n);
    ll ans = 0;
    int cnt = 0;
    vector<ll> dp;
    dp.push_back(1);
    for(int i = 1; i < n; i++){
        int sz = dp.size();
        if(a[i-1]+1 == a[i]){
            if(sz <= 1) dp.push_back(1);
            else dp.push_back(dp[sz-2]+1);
        }else if(a[i-1]+2 == a[i]){
            if(sz == 1) {
                ans += dp[0];
                dp.clear();
                dp.push_back(1);
            }else if(sz >= 2){
                dp.push_back(dp[sz-2]);
                dp.push_back(1);
            }
        }else{
            for(ll x : dp) ans += x;
            if(dp.size() >= 2) ans += dp[sz-2];
            dp.clear();
            dp.push_back(1);
        }
    }
    // cout << ans << endl;
    // for(ll x : dp) cout << x << ' ';
    // cout << endl;
    for(ll x : dp) ans += x;
    if(dp.size() >= 2) ans += dp[dp.size()-2];
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    input();
    solve();
}
0