結果

問題 No.1896 Arrays and XOR Procedure 2
ユーザー 👑 箱
提出日時 2022-04-08 22:09:22
言語 Kotlin
(1.9.10)
結果
AC  
実行時間 550 ms / 2,000 ms
コード長 1,697 bytes
コンパイル時間 22,086 ms
コンパイル使用メモリ 424,276 KB
実行使用メモリ 59,052 KB
最終ジャッジ日時 2023-08-19 00:42:00
合計ジャッジ時間 39,269 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 328 ms
52,628 KB
testcase_01 AC 311 ms
52,484 KB
testcase_02 AC 291 ms
54,712 KB
testcase_03 AC 473 ms
54,652 KB
testcase_04 AC 506 ms
54,304 KB
testcase_05 AC 523 ms
59,052 KB
testcase_06 AC 496 ms
54,240 KB
testcase_07 AC 496 ms
56,060 KB
testcase_08 AC 509 ms
56,872 KB
testcase_09 AC 506 ms
56,484 KB
testcase_10 AC 550 ms
54,536 KB
testcase_11 AC 500 ms
54,600 KB
testcase_12 AC 528 ms
54,668 KB
testcase_13 AC 498 ms
54,148 KB
testcase_14 AC 492 ms
56,376 KB
testcase_15 AC 515 ms
54,480 KB
testcase_16 AC 470 ms
54,324 KB
testcase_17 AC 439 ms
54,460 KB
testcase_18 AC 497 ms
54,540 KB
testcase_19 AC 400 ms
53,680 KB
testcase_20 AC 447 ms
53,960 KB
testcase_21 AC 406 ms
55,152 KB
testcase_22 AC 528 ms
56,644 KB
testcase_23 AC 516 ms
56,668 KB
testcase_24 AC 535 ms
58,736 KB
testcase_25 AC 528 ms
56,604 KB
testcase_26 AC 473 ms
56,328 KB
testcase_27 AC 477 ms
56,144 KB
testcase_28 AC 440 ms
55,992 KB
testcase_29 AC 453 ms
56,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
0