結果

問題 No.2397 ω冪
ユーザー lam6er
提出日時 2025-03-31 17:47:28
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,333 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 82,572 KB
実行使用メモリ 78,340 KB
最終ジャッジ日時 2025-03-31 17:48:35
合計ジャッジ時間 4,113 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 RE * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

def subtract_one(s):
    s_list = list(s)
    i = len(s_list) - 1
    while i >= 0 and s_list[i] == '0':
        s_list[i] = '1'
        i -= 1
    if i < 0:
        return '0'
    s_list[i] = '0'
    result = ''.join(s_list).lstrip('0')
    return result if result else '0'

def decompose(n_bin):
    if n_bin == '0':
        return ('0', 0)
    n_clean = n_bin.lstrip('0') or '0'
    b = 0
    for c in reversed(n_clean):
        if c == '0':
            b += 1
        else:
            break
    remaining = n_clean[:-b] if b > 0 else n_clean
    if not remaining:
        remaining = '0'
    s_minus_1 = subtract_one(remaining)
    a_bin = s_minus_1[:-1] if s_minus_1 != '0' else '0'
    if a_bin == '':
        a_bin = '0'
    return (a_bin, b)

def compare_ord(n_bin, m_bin):
    if n_bin == '0':
        return 'equal' if m_bin == '0' else 'less'
    if m_bin == '0':
        return 'greater'
    a_n, b_n = decompose(n_bin)
    a_m, b_m = decompose(m_bin)
    cmp_b = compare_ord(b_n, b_m)
    if cmp_b != 'equal':
        return cmp_b
    return compare_ord(a_n, a_m)

def clean_binary(s):
    s = s.lstrip('0')
    return s if s else '0'

n_str = input().strip()
m_str = input().strip()

n_bin = clean_binary(n_str)
m_bin = clean_binary(m_str)

result = compare_ord(n_bin, m_bin)
print("Yes" if result == 'less' else "No")
0