結果

問題 No.2374 ASKT Subsequences
ユーザー HIcoderHIcoder
提出日時 2023-07-24 12:10:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,718 bytes
コンパイル時間 1,064 ms
コンパイル使用メモリ 115,464 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-08 14:49:25
合計ジャッジ時間 2,163 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 1 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 2 ms
6,548 KB
testcase_15 AC 3 ms
6,548 KB
testcase_16 AC 2 ms
6,548 KB
testcase_17 AC 4 ms
6,548 KB
testcase_18 AC 7 ms
6,548 KB
testcase_19 AC 7 ms
6,548 KB
testcase_20 AC 12 ms
6,548 KB
testcase_21 AC 16 ms
6,548 KB
testcase_22 AC 10 ms
6,548 KB
testcase_23 AC 8 ms
6,548 KB
testcase_24 AC 8 ms
6,548 KB
testcase_25 AC 4 ms
6,548 KB
testcase_26 AC 27 ms
6,548 KB
testcase_27 AC 10 ms
6,548 KB
testcase_28 AC 35 ms
6,548 KB
testcase_29 AC 5 ms
6,548 KB
testcase_30 AC 12 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
真ん中二つをきめる際に全探索

のこりは二分探索
AC

*/
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include<random>
#include<bitset>
//#include<fstream>

using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=998244353;


int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    vector<vector<int>> idx(2000+1);
    for(int i=0;i<N;i++){
        cin>>A[i];    
        idx[A[i]].push_back(i);
    }


    ll cnt=0;

    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            //a[2]=A[i]とa[3]=A[j]と固定
           
            //
            int a2=A[i];
            int a3=A[j];
            int k=a2-a3;
            if(k<=0) continue;


            int a1=a2-(k+10);
            int a4=a3+(k+1);

            if(a1<1 || 2000<a4) continue;

            //[ begin, it)
            auto it=lower_bound(idx[a1].begin(),idx[a1].end(),i);
        
            

            ll c1= it -idx[a1].begin();

            //[it,end)
            ll c2=idx[a4].end() - upper_bound(idx[a4].begin(),idx[a4].end(),j);

            cnt+=c1*c2;

        }
    }

    /*

    auto check=[&](int idx){
        if(idx+3>=N) return false;
        ll k=A[idx+1]-(A[idx]+10);
        //if(A[idx+2]==A[idx]+10 && A[idx+3]==A[idx]+11+k){
        if(A[idx+2]==A[idx+1]-k && A[idx+3]==A[idx+2]+1+k){
            return true;
        }else{
            return false;
        }
    };

    int cnt=0;
    for(int i=0;i<N;i++){
        if(check(i)){
            cnt++;
        }
    }
    */

    cout<<cnt<<endl;

}
0