結果

問題 No.2766 Delicious Multiply Spice
ユーザー splash9494
提出日時 2024-08-15 14:01:59
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 989 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-08-15 14:02:02
合計ジャッジ時間 2,473 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 8
other AC * 28 RE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

# https://yukicoder.me/problems/no/2766

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