結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,548 KB
testcase_01 AC 7 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 9 ms
6,548 KB
testcase_04 AC 11 ms
6,548 KB
testcase_05 AC 11 ms
6,548 KB
testcase_06 AC 10 ms
6,548 KB
testcase_07 AC 45 ms
6,548 KB
testcase_08 AC 48 ms
6,548 KB
testcase_09 AC 44 ms
6,548 KB
testcase_10 AC 103 ms
6,548 KB
testcase_11 AC 58 ms
6,548 KB
testcase_12 AC 53 ms
6,548 KB
testcase_13 AC 53 ms
6,548 KB
testcase_14 AC 62 ms
6,548 KB
testcase_15 AC 66 ms
6,548 KB
testcase_16 AC 58 ms
6,548 KB
testcase_17 AC 135 ms
6,548 KB
testcase_18 AC 156 ms
6,548 KB
testcase_19 AC 158 ms
6,548 KB
testcase_20 AC 352 ms
6,548 KB
testcase_21 AC 396 ms
6,548 KB
testcase_22 AC 336 ms
6,548 KB
testcase_23 AC 159 ms
6,548 KB
testcase_24 AC 160 ms
6,548 KB
testcase_25 AC 5 ms
6,548 KB
testcase_26 AC 441 ms
6,548 KB
testcase_27 AC 6 ms
6,548 KB
testcase_28 AC 9 ms
6,548 KB
testcase_29 AC 433 ms
6,548 KB
testcase_30 AC 144 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
    ll maxA=-INF;
    ll minA=INF;
    for(int i=0;i<N;i++){
        cin>>A[i];
        maxA=max(maxA,A[i]);
        minA=min(minA,A[i]);    
    }


    
    /*
    遷移はあっているけどTLE
    */
   /*
    ll ans=0;

    for(ll k=1;k<=maxA-minA;k++){
        
        //dp[i][j]=j番目の要素がA[i]となる
        
        vector<vector<ll>> dp(N+1,vector<ll>(4,0));
        for(int i=0;i<N;i++){
            dp[i][0]=1;
        }
        
        for(int i=0;i<N;i++){
            for(int j=1;j<4;j++){
                if(j-1==0){
                    for(int x=0;x<i;x++){
                        if(A[i]==A[x]+(k+10)){
                            dp[i][j]+=dp[x][j-1];
                        }
                    }
                }else if(j-1==1){

                    for(int x=0;x<i;x++){
                        if(A[i]==A[x]-k){
                            dp[i][j]+=dp[x][j-1];
                        }
                    }


                }else if(j-1==2){

                    for(int x=0;x<i;x++){
                        if(A[i]==A[x]+(k+1)){
                            dp[i][j]+=dp[x][j-1];
                        }
                    }

                }


            }
        }

        for(int i=0;i<N;i++){
            
            ans+=dp[i][3];
    
        }


    }


    cout<<ans<<endl;

    */




    ll ans=0;

    for(ll k=1;k<=maxA-minA;k++){
        
        //dp[i][j]=j番目の要素がA[i]となる
        
        vector<vector<ll>> dp(N+1,vector<ll>(4,0));

        vector<vector<ll>> C(2001,vector<ll>(4,0));

        /*
        for(int i=0;i<N;i++){
            //dp[i][0]=1;

            C[A[i]][0]+=1;
        }
        */
        
      

       
        
        for(int i=0;i<N;i++){
            C[A[i]][0]+=1;
            
            for(int j=1;j<4;j++){
                if(j-1==0){
                    int pre=A[i]-(k+10);
                    
                    if(0<=pre && pre<=2000){
                        dp[i][j]+=C[pre][j-1];
                        C[A[i]][j]+=dp[i][j];
                    }

                    /*
                    for(int x=0;x<i;x++){
                        if(A[i]==A[x]+(k+10)){
                            dp[i][j]+=dp[x][j-1];
                        }
                    }
                    */
                   

                }else if(j-1==1){

                    int pre=A[i]+k;
                    
                    if(0<=pre && pre<=2000){
                        dp[i][j]+=C[pre][j-1];
                        C[A[i]][j]+=dp[i][j];

                    }

                    
                    /*
                    for(int x=0;x<i;x++){
                        if(A[i]==A[x]-k){
                            dp[i][j]+=dp[x][j-1];
                        }
                    }
                    */


                }else if(j-1==2){


                    
                    int pre=A[i]-(k+1);
                    
                    if(0<=pre && pre<=2000){
                        dp[i][j]+=C[pre][j-1];
                        C[A[i]][j]+=dp[i][j];

                    }

                    /*
                    for(int x=0;x<i;x++){
                        if(A[i]==A[x]+(k+1)){
                            dp[i][j]+=dp[x][j-1];
                        }
                    }
                    */

                }


            }
        }

        for(int i=0;i<N;i++){
            
            ans+=dp[i][3];
    
        }


    }


    cout<<ans<<endl;



}
0