結果

問題 No.2374 ASKT Subsequences
ユーザー ryohei22
提出日時 2023-07-08 13:17:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 554 ms / 2,000 ms
コード長 533 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,312 KB
実行使用メモリ 189,560 KB
最終ジャッジ日時 2024-07-22 08:47:46
合計ジャッジ時間 4,610 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict


"""
解説AC
	reference: https://www.youtube.com/watch?v=ImVYMpTuXiY

[方針]
a2 と a3 を固定する。
"""
N = int(input())
A = list(map(int, input().split()))

# s[i][j]: s[0]-s[i] に含まれる j の個数
s = []
cnt = defaultdict(int)
for i in A:
	cnt[i] += 1
	s.append(cnt.copy())

ans = 0
for i in range(1, N-2):
	a2 = A[i]
	for j in range(i+1, N-1):
		a3 = A[j]
		k = a2 - a3
		a1 = a2 - k - 10
		a4 = a3 + k + 1
		if 0 < k:
			ans += s[i-1][a1] * (s[-1][a4] - s[j][a4])
print(ans)
0