結果

問題 No.2374 ASKT Subsequences
ユーザー momoyuumomoyuu
提出日時 2023-07-08 01:03:39
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,753 bytes
コンパイル時間 1,224 ms
コンパイル使用メモリ 109,496 KB
実行使用メモリ 66,176 KB
最終ジャッジ日時 2023-09-29 02:36:54
合計ジャッジ時間 3,230 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,504 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
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 AC 21 ms
19,000 KB
testcase_26 WA -
testcase_27 AC 77 ms
66,148 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
using ll = long long;


template< typename T >
struct BIT2D{
    int H,W;
    vector<vector<T>> data;
    BIT2D(int h,int w):H(h),W(w),data(h+1,vector<T>(w+1,0)){}

    void add(int h,int w,T x){
        h++;w++;
        for(int i = h;i<=H;i+=i&(-i)){
            for(int j = w;j<=W;j+=j&(-j)){
                data[i][j] += x;
            }
        }
    }

    //sum of [l,r)
    T sum(int h1,int w1,int h2,int w2){
        return sum(h2,w2)-sum(h2,w1-1)-sum(h1-1,w2)+sum(h1-1,w1-1);
    }

    T sum(int h,int w){
        h++;w++;
        T now = 0;
        for(int i = h;i>0;i-=i&(-i)){
            for(int j = w;j>0;j-=j&(-j)){
                now += data[i][j];
            }
        }
        return now;
    }
};  

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i = 0;i<n;i++) cin>>a[i];
    ll ans = 0;
    vector<vector<ll>> s1(n+1,vector<ll>(n+1,0)),s2(n+1,vector<ll>(n+1,0));
    for(int i = 0;i<n;i++) for(int j = i+1;j<n;j++){
        if(a[j]==a[i]+10) {
            s1[i+1][j+1] ++;
        }
        if(a[j]==a[i]+1){
            s2[i+1][j+1]++;
        }
    }
    for(int i = 0;i<n;i++) for(int j = 0;j<=n;j++){
        s1[i+1][j] += s1[i][j];
        s2[i+1][j] += s2[i][j];
    }
    for(int i = 0;i<=n;i++) for(int j = 0;j<n;j++){
        s1[i][j+1] += s1[i][j];
        s2[i][j+1] += s2[i][j];
    }
    for(int i = 0;i<n;i++) for(int j = i+2;j<n;j++){
        if(a[j]==a[i]+10) { 
            ans += s2[j][n] - s2[i][n] - s2[j][j] + s2[i][j];
        }
        if(a[j]==a[i]+1){
            ans += s1[j][n] - s1[i][n] - s1[j][j] + s1[i][j];
        }
    }
    cout <<ans<<endl;

}

0