結果

問題 No.1047 Zero (Novice)
ユーザー kshiva1126kshiva1126
提出日時 2020-05-23 02:26:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 646 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2024-04-16 00:08:55
合計ジャッジ時間 1,554 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

def hoge(A, B, n, cnt):
    # Bが0なら回数を出力
    if B == 0:
        print(0)
        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