結果
問題 | No.152 貯金箱の消失 |
ユーザー | maspy |
提出日時 | 2020-02-24 19:16:33 |
言語 | Python3 (3.11.6 + numpy 1.26.0 + scipy 1.11.3) |
結果 |
AC
|
実行時間 | 336 ms / 5,000 ms |
コード長 | 1,087 bytes |
コンパイル時間 | 116 ms |
コンパイル使用メモリ | 10,780 KB |
実行使用メモリ | 37,140 KB |
最終ジャッジ日時 | 2023-08-02 13:29:28 |
合計ジャッジ時間 | 2,153 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 15 ms
7,792 KB |
testcase_01 | AC | 15 ms
7,792 KB |
testcase_02 | AC | 14 ms
7,828 KB |
testcase_03 | AC | 14 ms
7,824 KB |
testcase_04 | AC | 21 ms
8,480 KB |
testcase_05 | AC | 20 ms
8,648 KB |
testcase_06 | AC | 25 ms
8,700 KB |
testcase_07 | AC | 64 ms
12,884 KB |
testcase_08 | AC | 326 ms
36,804 KB |
testcase_09 | AC | 336 ms
37,140 KB |
testcase_10 | AC | 264 ms
30,504 KB |
testcase_11 | AC | 155 ms
20,880 KB |
ソースコード
#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% # import numpy as np # from numba import njit # %% def gen_pythagorean_triples(bound): """generate primitive pythagorean triples. Parameters ---------- bound : int upper bound of pelimeter of the triangle Yields ------- tuple(int, int, int) primitive pythagorean triangles """ if bound <= 12: return yield (3, 4, 5) stack = [(3, 4, 5)] while stack: a, b, c = stack.pop() for x, y, z in [ (a - 2 * b + 2 * c, 2 * a - b + 2 * c, 2 * a - 2 * b + 3 * c), (a + 2 * b + 2 * c, 2 * a + b + 2 * c, 2 * a + 2 * b + 3 * c), (-a + 2 * b + 2 * c, -2 * a + b + 2 * c, -2 * a + 2 * b + 3 * c)]: if x + y + z < bound: yield (x, y, z) stack.append((x, y, z)) # %% L = int(readline()) # %% N = L // 4 answer = len(list(gen_pythagorean_triples(N + 1))) print(answer)