結果

問題 No.1458 Segment Function
ユーザー LyricalMaestro
提出日時 2025-09-18 00:02:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,015 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 75,316 KB
最終ジャッジ日時 2025-09-18 00:02:09
合計ジャッジ時間 4,342 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

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

MOD = 10 ** 9 + 7

f_map = [6, 2, 5, 5, 4, 5, 6, 4, 7, 6]

def main():
    P, N = input().split()

    def func(p: str):
        answer = 0
        q = p
        if "-" == p[0]:
            answer += 1
            q = p[1:]
        
        for x in q:
            answer += f_map[int(x)]
        answer = str(answer)
        return answer

    a_map = {}
    p = P
    n = 0
    while p not in a_map:
        a_map[p] = n
        p = func(p)
        n += 1
    
    n_max = n
    n_start = a_map[p]
    if len(N) < 10:
        if int(N) <= n_start:
            for key, value in a_map.items():
                if value == int(N):
                    print(key)
                    return
    
    K = n_max - n_start
    x = (-n_start) % K
    for n in N:
        x += int(n) % K
    
    for key, value in a_map.items():
        if value - n_start == x:
            print(key)
            return
    




            



        




if __name__ == "__main__":
    main()
0