結果
問題 | No.1623 三角形の制作 |
ユーザー | gorugo30 |
提出日時 | 2021-05-05 13:52:58 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 528 ms / 2,000 ms |
コード長 | 2,646 bytes |
コンパイル時間 | 371 ms |
コンパイル使用メモリ | 82,120 KB |
実行使用メモリ | 230,356 KB |
最終ジャッジ日時 | 2024-07-18 16:23:08 |
合計ジャッジ時間 | 12,351 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 446 ms
205,696 KB |
testcase_01 | AC | 478 ms
205,696 KB |
testcase_02 | AC | 511 ms
212,104 KB |
testcase_03 | AC | 499 ms
211,896 KB |
testcase_04 | AC | 505 ms
212,196 KB |
testcase_05 | AC | 520 ms
223,212 KB |
testcase_06 | AC | 468 ms
215,984 KB |
testcase_07 | AC | 505 ms
211,992 KB |
testcase_08 | AC | 459 ms
216,452 KB |
testcase_09 | AC | 508 ms
212,624 KB |
testcase_10 | AC | 512 ms
229,260 KB |
testcase_11 | AC | 528 ms
211,920 KB |
testcase_12 | AC | 476 ms
216,300 KB |
testcase_13 | AC | 489 ms
214,744 KB |
testcase_14 | AC | 485 ms
214,732 KB |
testcase_15 | AC | 514 ms
230,168 KB |
testcase_16 | AC | 520 ms
230,048 KB |
testcase_17 | AC | 524 ms
230,356 KB |
testcase_18 | AC | 521 ms
222,376 KB |
testcase_19 | AC | 497 ms
210,192 KB |
testcase_20 | AC | 456 ms
205,696 KB |
ソースコード
MAXRGB = 3000 def solve(n, R, G, B): Rcnt = [0] * (MAXRGB + 1) Gcnt = [0] * (MAXRGB + 1) Bcnt = [0] * (MAXRGB + 1) for r in R: Rcnt[r] += 1 for g in G: Gcnt[g] += 1 for b in B: Bcnt[b] += 1 Rsum = [0] * (MAXRGB + 2) for i in range(MAXRGB + 1): Rsum[i + 1] = Rsum[i] + Rcnt[i] ans = 0 for g in range(1, MAXRGB + 1): for b in range(1, MAXRGB + 1): tmp = Rsum[min(MAXRGB + 1, g + b)] - Rsum[min(MAXRGB + 1, max(g, b, abs(g - b) + 1))] ans += tmp * Gcnt[g] * Bcnt[b] return ans def solve2d(n, R, G, B): Rcnt = [0] * (MAXRGB + 1) Gcnt = [0] * (MAXRGB + 1) Bcnt = [0] * (MAXRGB + 1) for r in R: Rcnt[r] += 1 for g in G: Gcnt[g] += 1 for b in B: Bcnt[b] += 1 C = [[0] * (2 * MAXRGB + 2) for i in range(MAXRGB + 2)] for i in range(1, MAXRGB + 1): for j in range(1, MAXRGB + 1): C[max(i, j) + 1][i + j + 1] += Gcnt[i] * Bcnt[j] for i in range(MAXRGB + 1): for j in range(2 * MAXRGB + 1): C[i + 1][j + 1] += C[i][j + 1] + C[i + 1][j] - C[i][j] ans = 0 for i in range(1, MAXRGB + 1): tmp = C[i + 1][2 * MAXRGB + 1] + C[1][i + 1] - C[i + 1][i + 1] - C[1][2 * MAXRGB + 1] ans += Rcnt[i] * tmp return ans def bruteforce(n, R, G, B): Rcnt = [0] * (MAXRGB + 1) Gcnt = [0] * (MAXRGB + 1) Bcnt = [0] * (MAXRGB + 1) for r in R: Rcnt[r] += 1 for g in G: Gcnt[g] += 1 for b in B: Bcnt[b] += 1 ans = 0 for i in range(1, MAXRGB + 1): if Rcnt[i] == 0: continue for j in range(1, min(MAXRGB + 1, i + 1)): if Gcnt[j] == 0: continue for k in range(1, min(MAXRGB + 1, i + 1)): if i + j > k and j + k > i and k + i > j: ans += Rcnt[i] * Gcnt[j] * Bcnt[k] return ans import random def gen(n): R = [random.randint(1, MAXRGB) for i in range(n)] G = [random.randint(1, MAXRGB) for i in range(n)] B = [random.randint(1, MAXRGB) for i in range(n)] return n, R, G, B def answer(): n = int(input()) R = list(map(int, input().split())) G = list(map(int, input().split())) B = list(map(int, input().split())) global MAXRGB MAXRGB = max(MAXRGB, max(R)) MAXRGB = max(MAXRGB, max(G)) MAXRGB = max(MAXRGB, max(B)) ans = solve2d(n, R, G, B) print(ans) def test(t): for i in range(t): n, R, G, B = gen(random.randint(1, 200000)) print(solve(n, R, G, B) - solve2d(n, R, G, B)) answer()