結果

問題 No.520 プロジェクトオイラーへの招待
ユーザー maspymaspy
提出日時 2020-04-16 15:54:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,448 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-04-09 19:14:09
合計ジャッジ時間 5,809 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,880 KB
testcase_01 AC 27 ms
10,752 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)))
0