結果

問題 No.1458 Segment Function
ユーザー yuruhiyayuruhiya
提出日時 2021-03-31 21:51:17
言語 Crystal
(1.14.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 588 bytes
コンパイル時間 17,619 ms
コンパイル使用メモリ 295,172 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-12 13:36:18
合計ジャッジ時間 14,824 ms
ジャッジサーバーID
(参考情報)
judge2 / judge
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

def func(a)
  if a.is_a?(Int64)
    res = 0i64
    if a < 0
      res += 1
      a = -a
    end
    if a < 10
      res += {6, 2, 5, 5, 4, 5, 6, 4, 7, 6}[a]
    else
      res += func(a % 10) + func(a // 10)
    end
    res
  else
    a.each_char.sum { |c|
      c == '-' ? 1i64 : func(c.to_i64)
    }
  end
end

a, n = read_line.split
n = n.to_i64
(n || 10**9).times do
  a = func(a)
  if a.is_a?(Int64) && {6, 5, 4}.any?(a)
    break
  end
end
puts a
0