結果

問題 No.1623 三角形の制作
ユーザー lam6er
提出日時 2025-03-20 18:47:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 1,158 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 142,260 KB
最終ジャッジ日時 2025-03-20 18:48:49
合計ジャッジ時間 4,356 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
r = list(map(int, input().split()))
g = list(map(int, input().split()))
b = list(map(int, input().split()))

max_val = 3000

# Initialize frequency arrays for green and blue
freq_g = [0] * (max_val + 1)
for num in g:
    freq_g[num] += 1

freq_b = [0] * (max_val + 1)
for num in b:
    freq_b[num] += 1

# Compute prefix sums for blue
prefix_b = [0] * (max_val + 2)  # prefix_b[x] is sum of frequencies up to x (1-based)
for x in range(1, max_val + 1):
    prefix_b[x] = prefix_b[x-1] + freq_b[x]

# Precompute pre[r] for all r from 1 to max_val
pre = [0] * (max_val + 1)  # pre[r] is the count for a red bar of length r

for r_val in range(1, max_val + 1):
    total = 0
    for g_val in range(1, r_val + 1):
        if freq_g[g_val] == 0:
            continue
        lb = r_val - g_val + 1
        lb = max(lb, 1)
        ub = r_val
        if lb > ub:
            continue
        count_b = prefix_b[ub] - prefix_b[lb - 1]
        total += freq_g[g_val] * count_b
    pre[r_val] = total

# Calculate the total answer by summing pre[r_i] for each r_i in the red array
answer = 0
for red_val in r:
    answer += pre[red_val]

print(answer)
0