結果

問題 No.303 割れません
ユーザー rpy3cpprpy3cpp
提出日時 2015-11-14 00:31:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 900 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 23,740 KB
最終ジャッジ日時 2023-10-11 17:33:14
合計ジャッジ時間 11,854 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,160 KB
testcase_01 AC 16 ms
8,368 KB
testcase_02 AC 16 ms
8,232 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

L = int(input())

def nCb(n, b):
    if b == 1:
        return max(n, 1)
    return math.factorial(n)//math.factorial(b)//math.factorial(n - b)
    

def solve(L):
    if L == 1:
        return 1, 1
    elif L == 2:
        return 4, 1
    if L & 1:
        return L, f(L)
    else:
        return L, f(L) - f(L//2) ** 2

def f(L):
    '''
    奇数の和がLとなる奇数の並べ方の数。
    '''
    if L & 1:
        return f_odd(L)
    else:
        return f_even(L)

def f_odd(L):
    if L == 1:
        return 1
    if L == 3:
        return 2
    cum = 2
    for k in range(3, L, 2):
        cum += nCb((L - k)//2 + k - 1, k - 1)
    return cum


def f_even(L):
    if L == 2:
        return 1
    if L == 4:
        return 3
    cum = 1
    for k in range(2, L, 2):
        cum += nCb((L - k)//2 + k - 1, k - 1)
    return cum


cost, pat = solve(L)
print(cost)
print(pat)
0