結果
| 問題 |
No.1312 Snake Eyes
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2020-12-10 07:43:38 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 470 bytes |
| コンパイル時間 | 41 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 12,544 KB |
| 最終ジャッジ日時 | 2024-09-19 15:26:37 |
| 合計ジャッジ時間 | 18,161 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 WA * 40 |
コンパイルメッセージ
Syntax OK
ソースコード
N = gets.to_i
def f(d, l, x)
return -Float::INFINITY if d >= x
num = 0
n = 1
l.times do
num += d * n
n *= x
end
num
end
L = N.to_s(2).size
ans = Float::INFINITY
L.downto(1) do |l|
1.upto(9) do |d|
ng = 1
ok = N + 1
while (ok - ng).abs >= 2
x = (ok + ng) / 2
if N <= f(d, l, x)
ok = x
else
ng = x
end
end
if f(d, l, ok) == N && ans > ok
ans = ok
end
end
end
puts ans
siman