結果
| 問題 |
No.1312 Snake Eyes
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2023-04-12 22:13:55 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 470 bytes |
| コンパイル時間 | 341 ms |
| コンパイル使用メモリ | 7,680 KB |
| 実行使用メモリ | 12,672 KB |
| 最終ジャッジ日時 | 2024-10-08 22:29:13 |
| 合計ジャッジ時間 | 16,547 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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