結果

問題 No.1880 Many Ways
ユーザー Yu_212Yu_212
提出日時 2022-04-12 16:14:13
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 371 ms / 2,000 ms
コード長 5,776 bytes
コンパイル時間 20,479 ms
コンパイル使用メモリ 446,760 KB
実行使用メモリ 59,576 KB
最終ジャッジ日時 2023-08-22 21:09:37
合計ジャッジ時間 41,062 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 363 ms
57,884 KB
testcase_01 AC 364 ms
57,860 KB
testcase_02 AC 367 ms
57,956 KB
testcase_03 AC 365 ms
58,388 KB
testcase_04 AC 371 ms
58,092 KB
testcase_05 AC 364 ms
59,576 KB
testcase_06 AC 366 ms
58,032 KB
testcase_07 AC 370 ms
58,116 KB
testcase_08 AC 368 ms
58,292 KB
testcase_09 AC 362 ms
58,280 KB
testcase_10 AC 366 ms
58,140 KB
testcase_11 AC 371 ms
57,916 KB
testcase_12 AC 368 ms
58,276 KB
testcase_13 AC 366 ms
58,276 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