結果
問題 | No.1623 三角形の制作 |
ユーザー | gorugo30 |
提出日時 | 2021-05-05 13:31:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 303 ms / 2,000 ms |
コード長 | 2,644 bytes |
コンパイル時間 | 911 ms |
コンパイル使用メモリ | 82,052 KB |
実行使用メモリ | 141,976 KB |
最終ジャッジ日時 | 2024-07-18 16:22:37 |
合計ジャッジ時間 | 6,787 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 181 ms
68,524 KB |
testcase_01 | AC | 182 ms
69,156 KB |
testcase_02 | AC | 251 ms
105,140 KB |
testcase_03 | AC | 251 ms
104,876 KB |
testcase_04 | AC | 249 ms
104,560 KB |
testcase_05 | AC | 303 ms
138,496 KB |
testcase_06 | AC | 204 ms
83,448 KB |
testcase_07 | AC | 254 ms
104,532 KB |
testcase_08 | AC | 210 ms
85,880 KB |
testcase_09 | AC | 247 ms
101,468 KB |
testcase_10 | AC | 288 ms
128,540 KB |
testcase_11 | AC | 265 ms
111,064 KB |
testcase_12 | AC | 226 ms
96,536 KB |
testcase_13 | AC | 230 ms
99,316 KB |
testcase_14 | AC | 231 ms
96,688 KB |
testcase_15 | AC | 301 ms
141,904 KB |
testcase_16 | AC | 301 ms
141,976 KB |
testcase_17 | AC | 302 ms
141,796 KB |
testcase_18 | AC | 301 ms
139,028 KB |
testcase_19 | AC | 249 ms
109,128 KB |
testcase_20 | AC | 184 ms
68,480 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 = solve(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()