結果

問題 No.1871 divisXor
ユーザー yudedako
提出日時 2022-03-16 00:41:47
言語 Scala(Beta)
(3.6.2)
結果
AC  
実行時間 904 ms / 2,000 ms
コード長 807 bytes
コンパイル時間 11,994 ms
コンパイル使用メモリ 248,040 KB
実行使用メモリ 64,572 KB
最終ジャッジ日時 2024-09-22 17:17:36
合計ジャッジ時間 43,132 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import scala.collection.mutable.*
import scala.io.StdIn.*
import scala.util.chaining.*
import scala.math.*
import scala.reflect.ClassTag
import scala.util.*
import scala.annotation.tailrec
import scala.collection.mutable

@main def main =
  val n = readLine().toLong
  def solve(target: Long): List[Long] =
    target match
      case 0L => Nil
      case 1L => 1::Nil
      case _ =>
        val prev = solve(target >> 1).map{_ << 1}
        val xor = prev.fold(0L){ (acc, v) => acc ^ ((v << 1) - 1)}
        if xor != target then
          1::prev
        else
          prev
  solve(n) match
    case Nil => println(-1)
    case result =>
      println(result.length)
      println(result.mkString(" "))
      System.err.println(result.map{i => (i << 1) - 1}.fold(0L){_ ^ _})
0