結果
| 問題 |
No.688 E869120 and Constructing Array 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-17 17:29:35 |
| 言語 | Nim (2.2.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 600 bytes |
| コンパイル時間 | 3,249 ms |
| コンパイル使用メモリ | 66,264 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-01 10:08:58 |
| 合計ジャッジ時間 | 3,977 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport] /home/judge/data/code/Main.nim(1, 26) Warning: imported and not used: 'algorithm' [UnusedImport]
ソースコード
import sequtils,strutils,algorithm,math,bitops
# a:0 b:1 で合計が2となるのがちょうどK通り
# 2^a * bC2 == k なる aとbを求める :: bC2 = b!/2!/(b-2)! = b*(b-1)/2
let k = stdin.readLine().parseInt()
proc factorOf2(n:int):int = n and -n
let maxA = k.factorOf2().countTrailingZeroBits()
for a in 0..maxA:
let c = k div (1 shl a)
let d = 1 + 8 * c
let dsqrt = d.float.sqrt.int
if dsqrt * dsqrt != d : continue
if (1 + dsqrt) mod 2 == 1 : continue
let b = (1 + dsqrt) div 2
if a + b > 30 : continue
echo a + b
echo ("0".repeat(a) & "1".repeat(b)).join(" ")
quit(0)