結果

問題 No.1880 Many Ways
ユーザー Yu_212Yu_212
提出日時 2022-04-12 16:14:13
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 442 ms / 2,000 ms
コード長 5,776 bytes
コンパイル時間 18,547 ms
コンパイル使用メモリ 465,228 KB
実行使用メモリ 55,924 KB
最終ジャッジ日時 2024-05-10 02:45:47
合計ジャッジ時間 40,176 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 398 ms
55,724 KB
testcase_01 AC 395 ms
55,824 KB
testcase_02 AC 388 ms
55,772 KB
testcase_03 AC 392 ms
55,760 KB
testcase_04 AC 396 ms
55,756 KB
testcase_05 AC 394 ms
55,924 KB
testcase_06 AC 388 ms
55,720 KB
testcase_07 AC 388 ms
55,636 KB
testcase_08 AC 391 ms
55,772 KB
testcase_09 AC 395 ms
55,652 KB
testcase_10 AC 386 ms
55,764 KB
testcase_11 AC 442 ms
55,644 KB
testcase_12 AC 388 ms
55,680 KB
testcase_13 AC 388 ms
55,804 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:94:13: warning: name shadowed: p
        var p = p
            ^
Main.kt:143:30: warning: parameter 'm' is never used
    fun nextCharGrid(n: Int, m: Int) = MutableList(n) { nextCharArray() }
                             ^

ソースコード

diff #

import ExtensionFunctions.testbit
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.system.measureNanoTime

typealias IPair = Pair<Int, Int>
typealias LPair = Pair<Long, Long>
typealias ILPair = Pair<Int, Long>
typealias List<E> = MutableList<E>
typealias LList<E> = List<List<E>>
typealias LLList<E> = List<LList<E>>
typealias LLLList<E> = List<LLList<E>>

val writer: PrintWriter = PrintWriter(System.out, false)
const val iinf: Int = 0x3fffffff
const val inf: Long = 0x1fffffffffffffff
const val eps: Double = 1e-9
const val mod: Int = 1000000007

fun solve() {
    val a = In.nextLong()
    val list = mutableListOf<IPair>()
    for (i in 0 until 40) {
        list.add(IPair(i * 3, (i + 1) * 3))
        list.add(IPair(i * 3 + 1, (i + 1) * 3))
        list.add(IPair(i * 3, (i + 1) * 3 + 1))
        list.add(IPair(i * 3 + 1, (i + 1) * 3 + 1))
        list.add(IPair(i * 3 + 2, (i + 1) * 3 + 2))
        if (a.testbit(i)) {
            list.add(IPair(i * 3, (i + 1) * 3 + 2))
        }
    }
    list.add(IPair(-1, 0))
    list.add(IPair(-1, 1))
    println(124, list.size)
    for ((x, y) in list) {
        println(x + 2, y + 2)
    }
}

fun main() {
    System.err.printf("%.1f ms", measureNanoTime {
        solve()
        writer.flush()
    } / 1000000.0)
}

fun <T> list(n1: Int, init: T): List<T> = MutableList(n1) { init }
fun <T> list(n1: Int, n2: Int, init: T): LList<T> = MutableList(n1) { list(n2, init) }
fun <T> list(n1: Int, n2: Int, n3: Int, init: T): LLList<T> = MutableList(n1) { list(n2, n3, init) }
fun <T> list(n1: Int, n2: Int, n3: Int, n4: Int, init: T): LLLList<T> = MutableList(n1) { list(n2, n3, n4, init) }
fun <T> list(n1: Int, init: (Int) -> T): List<T> = MutableList(n1) { i1 -> init(i1) }
fun <T> list(n1: Int, n2: Int, init: (Int, Int) -> T): LList<T> = MutableList(n1) { i1 -> MutableList(n2) { i2 -> init(i1, i2) } }
fun <T> list(n1: Int, n2: Int, n3: Int, init: (Int, Int, Int) -> T): LLList<T> = MutableList(n1) { i1 -> MutableList(n2) { i2 -> MutableList(n3) { i3 -> init(i1, i2, i3) } } }
fun <T> list(n1: Int, n2: Int, n3: Int, n4: Int, init: (Int, Int, Int, Int) -> T): LLLList<T> = MutableList(n1) { i1 -> MutableList(n2) { i2 -> MutableList(n3) { i3 -> MutableList(n4) { i4 -> init(i1, i2, i3, i4) } } } }
fun <T: Comparable<T>> minmax(a: T, b: T) = if (a <= b) Pair(a, b) else Pair(b, a)
fun min(vararg a: Int) = a.minOrNull()!!
fun max(vararg a: Int) = a.maxOrNull()!!
fun min(vararg a: Long) = a.minOrNull()!!
fun max(vararg a: Long) = a.maxOrNull()!!
fun <T: Comparable<T>> min(vararg a: T) = a.minOrNull()!!
fun <T: Comparable<T>> max(vararg a: T) = a.maxOrNull()!!
fun <T> println(list: LList<T>) = writer.println(list.joinToString("\n"))
fun println(vararg args: Any?) = writer.println(args.joinToString(" "))

object ExtensionFunctions {
    fun String.toDigitArray() = map { it - '0' }.toMutableList()

    fun List<Long>.accumulate(): List<Long> {
        val s = MutableList(size + 1) { 0L }
        for ((i, v) in this.withIndex()) {
            s[i + 1] = s[i] + v
        }
        return s
    }

    fun Int.testbit(i: Int) = this shr i and 1 == 1

    fun Long.testbit(i: Int) = this shr i and 1 == 1L

    fun Int.bitLength() = 32 - Integer.numberOfLeadingZeros(this)

    fun Long.bitLength() = 64 - java.lang.Long.numberOfLeadingZeros(this)

    fun Int.clamp(l: Int, r: Int) = coerceIn(l, r)

    fun Long.clamp(l: Long, r: Long) = coerceIn(l, r)

    operator fun String.times(n: Int) = repeat(n)

    fun Long.pow(p: Int): Long {
        var p = p
        var a = this
        var x = 1L
        while (p > 0) {
            if (p and 1 == 1) {
                x *= a
            }
            a *= a
            p = p shr 1
        }
        return x
    }

    fun <T> List<T>.swap(i: Int, j: Int) {
        val temp = this[j]
        this[j] = this[i]
        this[i] = temp
    }

    fun <T> List<T>.runLengthEncoding(): List<Pair<T, Int>> {
        val encoded: List<Pair<T, Int>> = mutableListOf()
        var count = 1
        for (i in 1..size) {
            if (i < size && this[i - 1] == this[i]) {
                count++
            } else {
                encoded.add(this[i - 1] to count)
                count = 1
            }
        }
        return encoded
    }
}

object In {
    private val reader = BufferedReader(InputStreamReader(System.`in`), 0x10000)
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        while (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray().toMutableList()
    fun nextCharGrid(n: Int, m: Int) = MutableList(n) { nextCharArray() }
    fun nextStringArray(n: Int, op: (String) -> String = { it }) = MutableList(n) { op(next()) }
    fun nextIntArray(n: Int, op: (Int) -> Int = { it }) = MutableList(n) { op(nextInt()) }
    fun nextIntMatrix(h: Int, w: Int, op: (Int) -> Int = { it }) = MutableList(h) { nextIntArray(w, op) }
    fun nextLongArray(n: Int, op: (Long) -> Long = { it }) = MutableList(n) { op(nextLong()) }
    fun nextLongMatrix(h: Int, w: Int, op: (Long) -> Long = { it }) = MutableList(h) { nextLongArray(w, op) }
    fun nextGraph(n: Int, m: Int, directed: Boolean = false): List<List<Int>> {
        val res: LList<Int> = list(n, 0, 0)
        for (i in 0 until m) {
            val u = nextInt() - 1
            val v = nextInt() - 1
            res[u].add(v)
            if (!directed) {
                res[v].add(u)
            }
        }
        return res
    }
}
0