結果

問題 No.2374 ASKT Subsequences
ユーザー SSRSSSRS
提出日時 2023-07-07 21:35:03
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 666 bytes
コンパイル時間 1,692 ms
コンパイル使用メモリ 171,984 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-07-21 17:18:49
合計ジャッジ時間 3,160 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
    A[i]--;
  }
  vector<int> cnt(2000, 0);
  vector<vector<int>> cnt2(2000, vector<int>(2000, 0));
  long long ans = 0;
  for (int i = N - 1; i >= 0; i--){
    for (int j = 0; j < i; j++){
      int k = A[i] - A[j] - 10;
      if (k > 0){
        int c = A[i] - k;
        int d = c + k + 1;
        if (0 <= c && c < 2000 && 0 <= d && d < 2000){
          ans += cnt2[c][d];
        }
      }
    }
    for (int j = 0; j < 2000; j++){
      cnt2[A[i]][j] += cnt[j];
    }
    cnt[A[i]]++;
  }
  cout << ans << endl;
}
0