結果

問題 No.2766 Delicious Multiply Spice
ユーザー splash9494
提出日時 2024-08-15 13:59:33
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 948 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 82,368 KB
実行使用メモリ 70,876 KB
最終ジャッジ日時 2024-08-15 13:59:37
合計ジャッジ時間 3,921 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 8
other RE * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import Self

class Node:
    def __init__(self, value, spice='', parent=None) -> None:
        self.value: int = value
        self.spice: str = spice
        self.parent: Self | None = parent
    
    def dig(self):
        if self.value == 1:
            return self
        
        if (self.value - 1) % 2 == 0:
            if goal := Node(value=(self.value - 1) / 2, spice='A', parent=self).dig():
                return goal
        if (self.value - 1) % 3 == 0:
            if goal := Node(value=(self.value - 1) / 3, spice='B', parent=self).dig():
                return goal
        
    def list_spices(self):
        spices = ['', self.spice]
        node = self
        while (p := node.parent) and p.spice:
            spices.append(p.spice)
            node = p
        return spices


if __name__ == '__main__':
    N = int(input())
    node = Node(value = N)
    goal = node.dig()
    print(''.join(goal.list_spices()))
0