結果
| 問題 |
No.2397 ω冪
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 15:25:34 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,660 bytes |
| コンパイル時間 | 290 ms |
| コンパイル使用メモリ | 81,700 KB |
| 実行使用メモリ | 62,116 KB |
| 最終ジャッジ日時 | 2025-04-16 15:27:20 |
| 合計ジャッジ時間 | 3,030 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 WA * 11 |
ソースコード
import sys
sys.setrecursionlimit(1 << 25)
def normalize_bin(s):
s = s.strip()
if not s:
return '0'
s = s.lstrip('0')
return s if s else '0'
def count_trailing_zeros(s):
cnt = 0
for c in reversed(s):
if c == '0':
cnt += 1
else:
break
return cnt
def remove_trailing_zeros(s):
idx = len(s)
for i in reversed(range(len(s))):
if s[i] == '1':
idx = i + 1
break
return s[:idx] if idx > 0 else '0'
def compute_a(k_str):
if k_str == '0':
return '0'
last_one = len(k_str) - 1
while last_one >= 0 and k_str[last_one] != '1':
last_one -= 1
if last_one < 0:
return '0'
subtracted = k_str[:last_one] + '0' + '0' * (len(k_str) - last_one - 1)
subtracted = subtracted.lstrip('0')
subtracted = subtracted if subtracted else '0'
a_str = subtracted[:-1] if len(subtracted) > 1 else '0'
return a_str
def compare(s1, s2):
s1 = normalize_bin(s1)
s2 = normalize_bin(s2)
if s1 == '0':
return -1 if s2 != '0' else 0
if s2 == '0':
return 1
b1 = count_trailing_zeros(s1)
b2 = count_trailing_zeros(s2)
b1_str = bin(b1)[2:]
b2_str = bin(b2)[2:]
cmp_b = compare(b1_str, b2_str)
if cmp_b != 0:
return cmp_b
k1_str = remove_trailing_zeros(s1)
k2_str = remove_trailing_zeros(s2)
if k1_str == '1' and k2_str == '1':
return 0
a1_str = compute_a(k1_str)
a2_str = compute_a(k2_str)
return compare(a1_str, a2_str)
n = input().strip()
m = input().strip()
result = compare(n, m)
print("Yes" if result == -1 else "No")
lam6er