結果
| 問題 |
No.520 プロジェクトオイラーへの招待
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-04-16 15:54:33 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,448 bytes |
| コンパイル時間 | 159 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 27,804 KB |
| 最終ジャッジ日時 | 2024-10-01 19:23:00 |
| 合計ジャッジ時間 | 5,756 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 TLE * 1 -- * 3 |
ソースコード
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import lru_cache
MOD = 10 ** 9 + 7
def cut(edges):
if edges == [1, 1, 1]:
raise StopIteration
n = len(edges)
# 辺上
for i in range(1, n):
x = edges[i]
for j in range(1, x):
if i == n - 1 and j != x - 1:
continue
if i == 1 and edges[0] == 1 and j != 1:
continue
left = [edges[0] - 1] + list(edges[1:i]) + [j, 1]
right = [1, x - j] + list(edges[i + 1:])
left = tuple(x for x in left if x > 0)
right = tuple(x for x in right if x > 0)
yield((left, right))
# 頂点
for i in range(2, n):
if i == 2 and edges[0] == 1 and edges[1] != 1:
continue
if i == n - 1 and edges[n - 1] != 1:
continue
left = [edges[0] - 1] + list(edges[1:i]) + [1]
right = [1] + list(edges[i:])
left = tuple(x for x in left if x)
right = tuple(x for x in right if x)
yield((left, right))
@lru_cache(None)
def f(edges):
if len(edges) < 3:
return 1
if edges == (1, 1, 1):
return 1
ret = sum(f(x) * f(y) for x, y in cut(edges))
ret %= MOD
return ret
N = int(readline())
m = map(int, read().split())
for a, b, c in zip(m, m, m):
print(f((a + 1, b + 1, c + 1)))
maspy