結果

問題 No.3456 Common Difference is D
コンテスト
ユーザー U10
提出日時 2026-02-28 15:44:12
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 986 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,528 ms
コンパイル使用メモリ 166,396 KB
実行使用メモリ 12,580 KB
最終ジャッジ日時 2026-02-28 15:44:18
合計ジャッジ時間 5,527 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 TLE * 1 -- * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

long long int make_and_count(long long int array[], int n, long long int d) {
    long long int count = 0;
    long long int table[n]={},table2[n]={};

    for(long long int i=0;i<n;i++) {
        for(long long int j=i+1;j<n;j++) {
            if(array[j] - array[i] == d) {
                table[i]++;
            }
        }
    }
    for(long long int j=n-1;j>=0;j--) {
        for(long long int i=j-1;i>=0;i--) {
            if(array[j] - array[i] == d) {
                table2[j]++;
            }
        }
    }
    for(long long int i=0;i<n;i++) {
        count += table2[i] * table[i];
    }
    return count;
}


int main(){
    long long int n;
    long long int d;
    
    cin >> n >> d;

    long long int array[n];
    
    for(long long int i=0;i<n;i++) cin >> array[i];

    long long int count = make_and_count(array, n, d);

    cout << count << endl;

    return 0;
}
0