結果

問題 No.2212 One XOR Matrix
ユーザー 👑 箱
提出日時 2023-02-10 22:09:16
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 759 ms / 2,000 ms
コード長 1,591 bytes
コンパイル時間 18,937 ms
コンパイル使用メモリ 424,272 KB
実行使用メモリ 88,136 KB
最終ジャッジ日時 2023-09-21 23:25:22
合計ジャッジ時間 26,014 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 331 ms
59,124 KB
testcase_01 AC 281 ms
52,608 KB
testcase_02 AC 331 ms
59,064 KB
testcase_03 AC 334 ms
57,368 KB
testcase_04 AC 331 ms
57,600 KB
testcase_05 AC 353 ms
59,460 KB
testcase_06 AC 418 ms
57,856 KB
testcase_07 AC 453 ms
58,044 KB
testcase_08 AC 562 ms
66,844 KB
testcase_09 AC 759 ms
88,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val n = nextInt()
    if (n == 1) {
        println(-1)
        return
    }
    val base = listOf(
        listOf(7, 14, 0, 8),
        listOf(4, 12, 2, 11),
        listOf(15, 9, 6, 1),
        listOf(13, 10, 5, 3)
    )
    val a = Array(1.shl(n)) { Array(1.shl(n)) { 0 } }
    for (i in 0 until 4) {
        for (j in 0 until 4) {
            a[i][j] = base[i][j]
        }
    }
    var size = 4
    for (iter in 0 until n - 2) {
        var num = 0
        for (i in 0 until size) {
            for (j in 0 until size) {
                a[i + size][j + size] = a[i][j] + size * size
                a[i][j + size] = num + size * size * 2
                a[i + size][j] = num + size * size * 3
                num++
            }
        }
        size *= 2
    }
    a.forEach { println(it.joinToString(" ")) }
}

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