結果

問題 No.1268 Fruit Rush 2
ユーザー tsutajtsutaj
提出日時 2020-10-23 22:56:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 2,294 bytes
コンパイル時間 994 ms
コンパイル使用メモリ 108,348 KB
実行使用メモリ 5,488 KB
最終ジャッジ日時 2023-09-28 17:26:17
合計ジャッジ時間 3,841 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 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 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 34 ms
4,936 KB
testcase_17 AC 30 ms
4,732 KB
testcase_18 AC 32 ms
4,508 KB
testcase_19 AC 31 ms
4,684 KB
testcase_20 AC 32 ms
4,560 KB
testcase_21 AC 30 ms
4,568 KB
testcase_22 AC 34 ms
4,816 KB
testcase_23 AC 34 ms
5,008 KB
testcase_24 AC 32 ms
4,620 KB
testcase_25 AC 31 ms
4,556 KB
testcase_26 AC 50 ms
5,288 KB
testcase_27 AC 50 ms
5,488 KB
testcase_28 AC 49 ms
5,432 KB
testcase_29 AC 49 ms
5,352 KB
testcase_30 AC 50 ms
5,292 KB
testcase_31 AC 43 ms
5,408 KB
testcase_32 AC 43 ms
5,356 KB
testcase_33 AC 46 ms
5,432 KB
testcase_34 AC 30 ms
5,384 KB
testcase_35 AC 46 ms
5,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; scanf("%d", &N);
    vector<ll> odd, even;
    for(int i=0; i<N; i++) {
        ll v; scanf("%lld", &v);
        if(v % 2) odd.emplace_back(v);
        else even.emplace_back(v);
    }

    sort(odd.begin(), odd.end());
    sort(even.begin(), even.end());
    vector<int> nxt_odd(odd.size(), 1), nxt_even(even.size(), 1);
    for(int i=(int)odd.size()-2; i>=0; i--) {
        if(odd[i+1] - odd[i] == 2) nxt_odd[i] = nxt_odd[i+1] + 1;
    }
    for(int i=(int)even.size()-2; i>=0; i--) {
        if(even[i+1] - even[i] == 2) nxt_even[i] = nxt_even[i+1] + 1;
    }

    ll ans = N;
    {
        int ie = 0;
        for(int io=0; io<(int)odd.size(); io++) {
            while(ie < (int)even.size() and odd[io] + 1 > even[ie]) ie++;
            if(ie >= (int)even.size()) continue;
            if(even[ie] != odd[io] + 1) continue;
            int len = nxt_even[ie];
            ans += len;
        }
    }
    {
        int io = 0;
        for(int ie=0; ie<(int)even.size(); ie++) {
            while(io < (int)odd.size() and even[ie] + 1 > odd[io]) io++;
            if(io >= (int)odd.size()) continue;
            if(odd[io] != even[ie] + 1) continue;
            int len = nxt_odd[io];
            ans += len;
        }
    }
    printf("%lld\n", ans);
    
    
    // 1 2 4 6 -> 3 4 6 -> 5 6 -> 7
    // 1 2 . 4 . 6
    // 2 3 . 5
    // 3 4 . 6
    return 0;
}
0