Submission #54111349


Source Code Expand

import MutableIntMap.Companion.mutableIntMapOf
import java.io.*
import java.util.*
import kotlin.collections.*
import kotlin.math.*

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()
    }
}

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

@JvmInline
value class ModInt private constructor(val value: Int) {
    operator fun plus(other: ModInt) = plus(other.value)
    operator fun plus(other: Int) = from(value + other)
    operator fun minus(other: ModInt) = minus(other.value)
    operator fun minus(other: Int) = from(value - other)
    operator fun times(other: ModInt) = times(other.value)
    operator fun times(other: Int) = from(value.toLong() * other)
    operator fun div(other: ModInt) = times(other.inv())
    operator fun div(other: Int) = div(from(other))

    fun pow(exponent: Int): ModInt {
        var ans = One
        var a = this
        var b = exponent
        while (b > 0) {
            if (b % 2 == 1) ans *= a
            a *= a
            b /= 2
        }
        return ans
    }

    fun inv(): ModInt = pow(MOD - 2)

    override fun toString() = value.toString()

    companion object {
        fun combination(n: Int, k: Int): ModInt {
            check(k in 0..n)
            return (1..k).fold(One) { acc, i -> acc * (n - i + 1) / i }
        }

        fun from(value: Int) = ModInt(value.mod())
        fun from(value: Long) = ModInt(value.mod())
        fun Int.mod() = mod(MOD)
        fun Long.mod() = mod(MOD)
        val Zero = from(0)
        val One = from(1)

        const val MOD = 998244353
    }
}

fun Array<ModInt>.sum(): ModInt {
    var sum = ModInt.Zero
    for (element in this) sum += element
    return sum
}

const val M = 1000000

fun solve() {
    val n = readInt()
    val a = readInts(n)
    val g = LongArray(M + 1)
    val f = LongArray(M + 1)
    for (i in a) g[i]++
    for (i in M downTo 1) if (g[i] > 0) {
        for (j in i..M step i) f[j] += g[i]
    }
    for (i in 1..M) f[i] += f[i - 1]
    var ans = 0L
    for (i in a) {
        ans += f[i] - g[i]
        g[i]--
    }
    println(ans)
}

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

Submission Info

Submission Time
Task E - Max/Min
User wangchaohui
Language Kotlin (Kotlin/JVM 1.8.20)
Score 475
Code Size 4102 Byte
Status AC
Exec Time 313 ms
Memory 73228 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 3
AC × 25
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All min_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
min_01.txt AC 72 ms 55096 KiB
random_01.txt AC 295 ms 71568 KiB
random_02.txt AC 241 ms 64928 KiB
random_03.txt AC 282 ms 71152 KiB
random_04.txt AC 302 ms 62772 KiB
random_05.txt AC 282 ms 71320 KiB
random_06.txt AC 276 ms 61040 KiB
random_07.txt AC 285 ms 71908 KiB
random_08.txt AC 230 ms 62220 KiB
random_09.txt AC 285 ms 72132 KiB
random_10.txt AC 246 ms 58264 KiB
random_11.txt AC 277 ms 71356 KiB
random_12.txt AC 272 ms 60180 KiB
random_13.txt AC 276 ms 71716 KiB
random_14.txt AC 242 ms 59268 KiB
random_15.txt AC 282 ms 72116 KiB
random_16.txt AC 239 ms 58356 KiB
random_17.txt AC 188 ms 56844 KiB
random_18.txt AC 225 ms 59872 KiB
random_19.txt AC 238 ms 73228 KiB
random_20.txt AC 245 ms 72396 KiB
random_21.txt AC 313 ms 72556 KiB
sample_01.txt AC 74 ms 55404 KiB
sample_02.txt AC 76 ms 55376 KiB
sample_03.txt AC 66 ms 55188 KiB