結果

問題 No.2374 ASKT Subsequences
ユーザー NP
提出日時 2023-07-08 08:26:21
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,138 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 82,724 KB
実行使用メモリ 82,704 KB
最終ジャッジ日時 2024-07-22 04:15:56
合計ジャッジ時間 5,701 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 TLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

def find_first_greater_than_m(sorted_list, m):
    left = 0
    right = len(sorted_list) - 1
    result = -1
    while left <= right:
        mid = (left + right) // 2
        if sorted_list[mid] > m:
            result = mid
            right = mid - 1
        else:
            left = mid + 1
    return result
#対数時間だから許して...
def count_asakatsu_subsequences(N, A):
    cnt = 0
    indices = {}
    for i, a in enumerate(A):
        if a not in indices:
            indices[a] = []
        indices[a].append(i)
    for i in range(N - 3):
        for j in range(i + 1, N - 2):
            k = A[j] - A[i] - 10
            if k > 0:
                m_values = indices.get(A[j] - k, [])
                for m in m_values:
                    if m > j:
                        n_values = indices.get(A[m] + k + 1, [])
                        first_n = find_first_greater_than_m(n_values, m)
                        if first_n != -1:
                            cnt += len(n_values[first_n:])
    return cnt

N = int(input())
A = list(map(int, input().split()))

result = count_asakatsu_subsequences(N, A)

print(result)

0