結果

問題 No.1268 Fruit Rush 2
ユーザー milanis48663220milanis48663220
提出日時 2020-10-23 23:17:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 985 bytes
コンパイル時間 765 ms
コンパイル使用メモリ 84,828 KB
実行使用メモリ 6,652 KB
最終ジャッジ日時 2023-09-28 18:29:09
合計ジャッジ時間 3,304 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 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 44 ms
6,500 KB
testcase_27 AC 45 ms
6,568 KB
testcase_28 AC 45 ms
6,572 KB
testcase_29 AC 45 ms
6,588 KB
testcase_30 AC 44 ms
6,512 KB
testcase_31 AC 38 ms
6,496 KB
testcase_32 AC 39 ms
6,564 KB
testcase_33 AC 43 ms
6,516 KB
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

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];
}

ll dp[200000];

void solve(){
    sort(a, a+n);
    ll ans = 0;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(i == 0 || a[i-1]+1 < a[i]){
            if(cnt >= 2){
                ans += dp[i-2];
            }
            dp[i] = 1;
            cnt = 1;
        }else{
            if(cnt == 1){
                dp[i] = 1;
            }else{
                dp[i] = dp[i-2]+1;
            }
            cnt++;
        }
        ans += dp[i];
        // cout << dp[i] << ' ';
    }
    if(cnt >= 2){
        ans += dp[n-2];
    }
    // cout << endl;
    cout << ans << endl;
}

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