Submission #53844893


Source Code Expand

import java.io.*
import java.util.*
import kotlin.collections.*

val INPUT: InputStream = System.`in`
val OUTPUT: PrintStream = System.out

val _reader = INPUT.bufferedReader()

var _tokenizer: StringTokenizer = StringTokenizer("")
fun read(): String {
    while (!_tokenizer.hasMoreTokens()) {
        _tokenizer = StringTokenizer(_reader.readLine() ?: return "", " ")
    }
    return _tokenizer.nextToken()
}

fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readInts(n: Int) = List(n) { readInt() }
fun readIntArray(n: Int) = IntArray(n) { readInt() }
fun readDoubles(n: Int) = List(n) { readDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }
fun readLongs(n: Int) = List(n) { readLong() }
fun readLongArray(n: Int) = LongArray(n) { readLong() }

val _writer = PrintWriter(OUTPUT, false)
inline fun output(block: PrintWriter.() -> Unit) {
    _writer.apply(block).flush()
}

class MutableIntMap<K> : LinkedHashMap<K, Int>() {
    override operator fun get(key: K): Int = super.get(key) ?: 0

    fun increment(key: K, value: Int = 1) {
        this[key] = this[key] + value
    }

    companion object {
        fun <K> mutableIntMapOf(vararg pairs: Pair<K, Int>) =
            MutableIntMap<K>().apply { putAll(pairs) }
    }
}

typealias Pii = Pair<Int, Int>

fun readPii() = readInt() to readInt()
fun readPiis(n: Int) = List(n) { readPii() }

infix fun Int.hasBit(i: Int): Boolean = this and (1 shl i) > 0
infix fun Int.xorBit(i: Int): Int = this xor (1 shl i)
infix fun Long.hasBit(i: Int): Boolean = this and (1L shl i) > 0
infix fun Long.xorBit(i: Int): Long = this xor (1L shl i)

fun largerStackSize(stackSizeMegaBytes: Int = 100, action: () -> Unit) {
    Thread(null, action, "", 1024L * 1024 * stackSizeMegaBytes).apply {
        start()
        join()
    }
}

// #################################################################################################

fun solve() {
    val n = readInt()
    val rowCount = IntArray(n)
    val columnCount = IntArray(n)
    var f = 0
    var s = 0
    val t = readInt()
    val a = readInts(t)
    for (i in a.indices) {
        val x = a[i] - 1
        val row = x / n
        val column = x % n
        if (++rowCount[row] == n || ++columnCount[column] == n || row == column && ++f == n ||
            row + column == n - 1 && ++s == n
        ) {
            println(i + 1)
            return
        }
    }
    println(-1)
}

fun main() {
//    repeat(readInt()) { solve() }
    solve()
}

Submission Info

Submission Time
Task C - Bingo 2
User wangchaohui
Language Kotlin (Kotlin/JVM 1.8.20)
Score 300
Code Size 2669 Byte
Status AC
Exec Time 243 ms
Memory 61268 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 39
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 44 ms 37692 KiB
00_sample_01.txt AC 44 ms 37712 KiB
00_sample_02.txt AC 45 ms 37696 KiB
01_random_00.txt AC 44 ms 37736 KiB
01_random_01.txt AC 44 ms 37688 KiB
01_random_02.txt AC 44 ms 37588 KiB
01_random_03.txt AC 44 ms 37696 KiB
01_random_04.txt AC 57 ms 38056 KiB
01_random_05.txt AC 48 ms 37716 KiB
01_random_06.txt AC 47 ms 37664 KiB
01_random_07.txt AC 44 ms 37652 KiB
01_random_08.txt AC 203 ms 60616 KiB
01_random_09.txt AC 204 ms 60832 KiB
01_random_10.txt AC 200 ms 60828 KiB
01_random_11.txt AC 203 ms 61112 KiB
01_random_12.txt AC 200 ms 60192 KiB
01_random_13.txt AC 204 ms 60324 KiB
01_random_14.txt AC 190 ms 59944 KiB
01_random_15.txt AC 204 ms 60016 KiB
01_random_16.txt AC 204 ms 60820 KiB
01_random_17.txt AC 243 ms 61136 KiB
01_random_18.txt AC 204 ms 60552 KiB
01_random_19.txt AC 204 ms 61016 KiB
01_random_20.txt AC 201 ms 60868 KiB
01_random_21.txt AC 205 ms 61148 KiB
01_random_22.txt AC 200 ms 60928 KiB
01_random_23.txt AC 195 ms 60828 KiB
01_random_24.txt AC 208 ms 60104 KiB
01_random_25.txt AC 204 ms 60868 KiB
01_random_26.txt AC 205 ms 60992 KiB
01_random_27.txt AC 237 ms 60824 KiB
01_random_28.txt AC 204 ms 60828 KiB
01_random_29.txt AC 196 ms 60416 KiB
01_random_30.txt AC 204 ms 60840 KiB
01_random_31.txt AC 203 ms 60796 KiB
01_random_32.txt AC 204 ms 60424 KiB
01_random_33.txt AC 199 ms 60688 KiB
01_random_34.txt AC 213 ms 61268 KiB
01_random_35.txt AC 206 ms 60616 KiB