結果

問題 No.1458 Segment Function
ユーザー yuruhiyayuruhiya
提出日時 2021-03-31 21:51:17
言語 Crystal
(1.11.2)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 588 bytes
コンパイル時間 15,651 ms
コンパイル使用メモリ 293,112 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 17:38:49
合計ジャッジ時間 13,285 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 6 ms
5,376 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 5 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 4 ms
5,376 KB
testcase_34 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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