結果

問題 No.528 10^9と10^9+7と回文
ユーザー cympfhcympfh
提出日時 2017-06-20 19:55:18
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 595 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 19,360 KB
最終ジャッジ日時 2024-04-10 06:26:43
合計ジャッジ時間 3,593 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
19,104 KB
testcase_01 AC 79 ms
12,160 KB
testcase_02 AC 79 ms
12,288 KB
testcase_03 AC 80 ms
12,288 KB
testcase_04 AC 80 ms
12,160 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

K = 1000000000
L = 1000000007

def pow10(m)
  a, b = 1, 1
  m.times do
    a = (a * 10) % K
    b = (b * 10) % L
  end
  [a, b]
end

def num(keta)
  return [1, 1] unless keta.positive?
  a, b = pow10((keta - 1) / 2)
  a = (a * 9) % K
  b = (b * 9) % K
  [a, b]
end

m = gets.chomp
head = m[0].to_i
tail = m[-1].to_i

if m.size == 1
  p head
  p head
  exit
end

a, b = 0, 0

c = head > tail ?  (head - 1) * (head - 1) : head * head
e, f = num(m.size - 2)
a = (a + c * e) % K
b = (b + c * f) % K

(m.size - 1).times do |i|
  da, db = num(i + 1)
  a = (a + da) % K
  b = (b + db) % L
end

p a
p b
0