結果

問題 No.1268 Fruit Rush 2
ユーザー chocoruskchocorusk
提出日時 2020-10-25 03:20:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 1,736 bytes
コンパイル時間 2,935 ms
コンパイル使用メモリ 133,188 KB
実行使用メモリ 13,296 KB
最終ジャッジ日時 2023-09-28 22:10:43
合計ジャッジ時間 5,889 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 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,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 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 AC 68 ms
4,576 KB
testcase_17 AC 59 ms
4,384 KB
testcase_18 AC 63 ms
4,632 KB
testcase_19 AC 63 ms
4,388 KB
testcase_20 AC 61 ms
4,380 KB
testcase_21 AC 60 ms
4,512 KB
testcase_22 AC 68 ms
4,648 KB
testcase_23 AC 69 ms
4,660 KB
testcase_24 AC 62 ms
4,436 KB
testcase_25 AC 60 ms
4,460 KB
testcase_26 AC 116 ms
4,876 KB
testcase_27 AC 117 ms
4,896 KB
testcase_28 AC 116 ms
5,004 KB
testcase_29 AC 116 ms
4,952 KB
testcase_30 AC 116 ms
4,876 KB
testcase_31 AC 99 ms
13,296 KB
testcase_32 AC 99 ms
13,184 KB
testcase_33 AC 157 ms
13,156 KB
testcase_34 AC 71 ms
12,808 KB
testcase_35 AC 140 ms
12,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
typedef pair<int, int> P;
ll solve(vector<ll> v){
    vector<ll> v1, v0, w0, w1;
    for(auto x:v){
        if(x&1) v1.push_back(x), w1.push_back(x);
        else v0.push_back(x), w0.push_back(x);
    }
    for(int i=0; i<v0.size(); i++) v0[i]-=2*i;
    for(int i=0; i<v1.size(); i++) v1[i]-=2*i;
    ll ans=0;
    for(int i=0; i<v0.size(); i++){
        ll x=w0[i];
        int t=lower_bound(w1.begin(), w1.end(), x+1)-w1.begin();
        if(t==w1.size() || w1[t]>x+1) continue;
        int u=upper_bound(v1.begin(), v1.end(), v1[t])-v1.begin();
        ans+=u-t;
    }
    for(int i=0; i<v1.size(); i++){
        ll x=w1[i];
        int t=lower_bound(w0.begin(), w0.end(), x+1)-w0.begin();
        if(t==w0.size() || w0[t]>x+1) continue;
        int u=upper_bound(v0.begin(), v0.end(), v0[t])-v0.begin();
        ans+=u-t;
    }
    return ans;
}
int main()
{
    int n; cin>>n;
    ll a[200020];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    sort(a, a+n);
    vector<ll> v;
    v.push_back(a[0]);
    ll ans=n;
    for(int i=1; i<n; i++){
        if(a[i]-a[i-1]>2){
            ans+=solve(v);
            v.clear();
        }
        v.push_back(a[i]);
    }
    ans+=solve(v);
    cout<<ans<<endl;
    return 0;
}
0