結果

問題 No.1047 Zero (Novice)
ユーザー kshiva1126kshiva1126
提出日時 2020-05-23 02:28:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 648 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-04-16 00:11:45
合計ジャッジ時間 1,678 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,624 KB
testcase_01 AC 30 ms
10,496 KB
testcase_02 AC 31 ms
10,624 KB
testcase_03 AC 30 ms
10,624 KB
testcase_04 AC 29 ms
10,496 KB
testcase_05 AC 29 ms
10,752 KB
testcase_06 AC 29 ms
10,496 KB
testcase_07 AC 31 ms
10,624 KB
testcase_08 WA -
testcase_09 AC 30 ms
10,624 KB
testcase_10 AC 29 ms
10,752 KB
testcase_11 AC 30 ms
10,496 KB
testcase_12 AC 29 ms
10,752 KB
testcase_13 RE -
testcase_14 AC 30 ms
10,752 KB
testcase_15 AC 30 ms
10,624 KB
testcase_16 AC 30 ms
10,496 KB
testcase_17 AC 30 ms
10,624 KB
testcase_18 AC 29 ms
10,496 KB
testcase_19 AC 30 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def fuga(A, B, n):
    return (A * n) + B

def hoge(A, B, n, cnt):
    # Bが0なら回数を出力
    if B == 0:
        print(1)
        return

    # 両方共+ or -
    if (A > 0 and B > 0) or (A < 0 and B < 0):
        print(-1)
        return

    n_1 = fuga(A, B, n)
    # 計算結果が0になるとき回数を出力
    if n_1 == 0:
        print(cnt)
        return

    n_2 = fuga(A, B, n_1)
    # 単調増加 or 単調減少の場合-1
    if (n_1 >= n and n_2 >= n_1) or (n >= n_1 and n_1 >= n_2):
        print(-1)
        return

    n = n_1
    hoge(A, B, n, cnt + 1)

s = list(map(int, input().split()))
hoge(s[0], s[1], 0, 1)
0