結果

問題 No.375 立方体のN等分 (1)
ユーザー ebicochinealebicochineal
提出日時 2016-06-16 16:28:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 254 ms / 5,000 ms
コード長 1,405 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 8,216 KB
最終ジャッジ日時 2023-08-02 01:41:21
合計ジャッジ時間 2,816 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,076 KB
testcase_01 AC 15 ms
8,104 KB
testcase_02 AC 16 ms
8,124 KB
testcase_03 AC 14 ms
8,216 KB
testcase_04 AC 15 ms
8,044 KB
testcase_05 AC 15 ms
8,116 KB
testcase_06 AC 15 ms
8,108 KB
testcase_07 AC 15 ms
8,104 KB
testcase_08 AC 15 ms
8,124 KB
testcase_09 AC 18 ms
8,068 KB
testcase_10 AC 18 ms
8,036 KB
testcase_11 AC 16 ms
8,120 KB
testcase_12 AC 16 ms
8,044 KB
testcase_13 AC 15 ms
8,116 KB
testcase_14 AC 254 ms
8,044 KB
testcase_15 AC 16 ms
8,208 KB
testcase_16 AC 17 ms
8,068 KB
testcase_17 AC 23 ms
8,124 KB
testcase_18 AC 248 ms
8,116 KB
testcase_19 AC 16 ms
8,116 KB
testcase_20 AC 16 ms
8,120 KB
testcase_21 AC 15 ms
8,044 KB
testcase_22 AC 93 ms
8,060 KB
testcase_23 AC 19 ms
8,064 KB
testcase_24 AC 16 ms
8,068 KB
testcase_25 AC 27 ms
8,040 KB
testcase_26 AC 33 ms
8,068 KB
testcase_27 AC 16 ms
8,168 KB
testcase_28 AC 30 ms
8,108 KB
testcase_29 AC 41 ms
8,044 KB
testcase_30 AC 33 ms
8,156 KB
testcase_31 AC 28 ms
8,164 KB
testcase_32 AC 39 ms
8,116 KB
testcase_33 AC 17 ms
8,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(n):
    l = []
    c = 2
    a = 0
    while c * c <= n:
        if n % c == 0:
            n //= c
            l += [c]
        else:
            c += 1 + a
            a = 1
    if n > 1 : l += [n]
    return l


def e0(a, b, c, i):
    global tmin
    s = sum([a, b, c])
    if i < 0:
        if s < tmin : tmin = s
        return
    if s > tmin : return
    e2(a*l[i], b, c, i-1)

def e3(a, b, c, i):
    global tmin
    s = sum([a, b, c])
    if i < 0:
        if s < tmin : tmin = s
        return
    if s > tmin : return
    e3(a*l[i], b, c, i-1)
    e3(a, b*l[i], c, i-1)
    e3(a, b, c*l[i], i-1)

def e1(a, b, c, i):
    global tmin
    s = sum([a, b, c])
    if i < 0:
        if s < tmin : tmin = s
        return
    if s > tmin : return
    e2(a*l[i], b, c, i-1)
    
def e2(a, b, c, i):
    global tmin
    s = sum([a, b, c])
    if i < 0:
        if s < tmin : tmin = s
        return
    if s > tmin : return
    e2(a*l[i], b, c, i-1)
    e3(a, b*l[i], c, i-1)

tmin = 0
N = int(input())
p = f(N)
if len(p) > 3:
    tmin = N - 1
    b = 1
    while b:
        b = 0
        l = []
        for i in set(p):
            if p.count(i) > 3:
                l += [i]*(p.count(i)-2)
                l += [i*i]
                b = 1
            else:
                l += [i]*(p.count(i))
        p = l
    e0(1, 1, 1, len(p)-1)
    print(tmin-3, N-1)
else:
    print(sum(p)-len(p), N-1)
0