結果
| 問題 |
No.1896 Arrays and XOR Procedure 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-04-08 22:09:22 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 522 ms / 2,000 ms |
| コード長 | 1,697 bytes |
| コンパイル時間 | 15,708 ms |
| コンパイル使用メモリ | 446,368 KB |
| 実行使用メモリ | 62,848 KB |
| 最終ジャッジ日時 | 2024-11-28 12:49:03 |
| 合計ジャッジ時間 | 32,782 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
import java.io.PrintWriter
import java.util.*
import kotlin.math.*
fun PrintWriter.solve() {
val n = nextInt()
val a = Array(n) { nextInt() }
val b = Array(n) { nextInt() }
val pqa = PriorityQueue<Pair<Int, Int>> { x, y -> y.first.compareTo(x.first) }
for (i in 0 until n) {
pqa.add(a[i] to i + 1)
}
val pqb = PriorityQueue<Pair<Int, Int>> { x, y -> x.first.compareTo(y.first) }
for (i in 0 until n) {
pqb.add(b[i] to i + 1)
}
val lst = mutableListOf<Triple<Int, Int, Int>>()
for (i in 0 until 10000) {
val (va, ia) = pqa.poll()
val (vb, ib) = pqb.poll()
if (va < vb) break
val v = va xor vb
if (va > v) {
lst.add(Triple(1, ia, ib))
pqa.add(v to ia)
pqb.add(vb to ib)
} else {
lst.add(Triple(2, ia, ib))
pqa.add(va to ia)
pqb.add(v to ib)
}
}
println(lst.size)
for ((x, y, z) in lst) {
println("$x $y $z")
}
}
fun main() {
Thread(null, {
val writer = PrintWriter(System.out, false)
writer.solve()
writer.flush()
}, "solve", abs(1L.shl(26)))
.apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
.apply { start() }.join()
}
// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()
fun next(): String {
while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
return st.nextToken()
}
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()
fun nextDouble() = next().toDouble()
// endregion