結果

問題 No.1946 ロッカーの問題
ユーザー 👑 箱
提出日時 2022-05-20 22:15:58
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 1,059 ms / 3,000 ms
コード長 1,633 bytes
コンパイル時間 17,662 ms
コンパイル使用メモリ 441,308 KB
実行使用メモリ 78,892 KB
最終ジャッジ日時 2023-10-20 12:59:55
合計ジャッジ時間 27,367 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 285 ms
59,512 KB
testcase_01 AC 286 ms
59,512 KB
testcase_02 AC 313 ms
60,168 KB
testcase_03 AC 958 ms
78,892 KB
testcase_04 AC 322 ms
60,204 KB
testcase_05 AC 422 ms
62,000 KB
testcase_06 AC 389 ms
61,928 KB
testcase_07 AC 421 ms
61,948 KB
testcase_08 AC 615 ms
65,956 KB
testcase_09 AC 756 ms
76,048 KB
testcase_10 AC 777 ms
74,300 KB
testcase_11 AC 363 ms
61,340 KB
testcase_12 AC 535 ms
61,288 KB
testcase_13 AC 297 ms
57,408 KB
testcase_14 AC 297 ms
57,408 KB
testcase_15 AC 310 ms
59,484 KB
testcase_16 AC 306 ms
59,504 KB
testcase_17 AC 742 ms
65,992 KB
testcase_18 AC 1,059 ms
72,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

fun PrintWriter.solve() {
    val n = nextInt()
    val m = nextInt()
    val a = Array(m) { nextInt() }
    val set = a.toSet()
    val isopen = Array(n + 1) { false }
    var count = 0
    for (i in n downTo 1) {
        if (set.contains(i) xor isopen[i]) {
            // region divisors
            val number = i
            val divs = mutableListOf<Int>()
            var divisor = 1
            while (divisor * divisor <= number) {
                if (number % divisor == 0) {
                    divs.add(divisor)
                    if (divisor * divisor != number) {
                        divs.add(number / divisor)
                    }
                }
                divisor++
            }
            // endregion
            for (d in divs) {
                isopen[d] = !isopen[d]
            }
        } else {
            count++
        }
    }
    println(count)
}

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