結果

問題 No.1946 ロッカーの問題
ユーザー ripityripity
提出日時 2022-05-20 22:55:05
言語 Kotlin
(1.9.10)
結果
AC  
実行時間 1,520 ms / 3,000 ms
コード長 3,348 bytes
コンパイル時間 19,713 ms
コンパイル使用メモリ 456,028 KB
実行使用メモリ 142,200 KB
最終ジャッジ日時 2023-10-20 13:46:46
合計ジャッジ時間 39,084 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 318 ms
51,904 KB
testcase_01 AC 312 ms
51,904 KB
testcase_02 AC 1,445 ms
138,264 KB
testcase_03 AC 1,499 ms
142,200 KB
testcase_04 AC 1,425 ms
138,268 KB
testcase_05 AC 1,119 ms
105,624 KB
testcase_06 AC 1,196 ms
111,796 KB
testcase_07 AC 937 ms
100,848 KB
testcase_08 AC 773 ms
72,492 KB
testcase_09 AC 1,356 ms
119,764 KB
testcase_10 AC 1,295 ms
116,668 KB
testcase_11 AC 415 ms
57,272 KB
testcase_12 AC 921 ms
80,448 KB
testcase_13 AC 312 ms
51,900 KB
testcase_14 AC 313 ms
51,896 KB
testcase_15 AC 423 ms
57,736 KB
testcase_16 AC 309 ms
51,904 KB
testcase_17 AC 962 ms
87,168 KB
testcase_18 AC 1,520 ms
122,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

fun main() {
    
    // val T = nextInt()
    // repeat(T) {solve()}
    // pw.flush()
    
    solve()
    pw.flush()
    
}

fun solve() {
    
    val N = nextInt()
    val M = nextInt()
    val hs = HashSet<Int>()
    var mul = Array<Int>(N+1) {0}
    val div = Array(N+1) { mutableListOf<Int>() }
    var ans = 0
    repeat(M) { hs.add(nextInt()) }
    
    for( i in 1..N ) {
        for( j in 1..N ) {
            if( i*j > N ) break
            mul[i]++
            div[i*j].add(i)
        }
    }
    
    for( i in N downTo 1 ) {
        // pw.println("::::$i")
        // pw.println(hs.contains(i))
        // pw.println(mul[i]%2 == 1)
        if( hs.contains(i) xor ( mul[i]%2 == 1 ) ) {
            // pw.println("$i ${div[i]}")
            ans++
            for( d in div[i] ) mul[d]++
        }
    }
    
    pw.println(ans)
    
}

fun printArray(a: Array<Long>) {
    
    a.forEach{ print("$it ") }
    println()
    
}

/* struct begin */

data class Pii(val fi: Int, val se: Int)
data class Edge(val from: Int, val to: Int, val w: Long)

class BinaryIndexedTree(n: Int) {
    
    val N = n
    var a = Array<Long>(N+1) {0L}
    
    fun sum(i: Int): Long {
        
        var idx = i+1
        var res = 0L
        while( idx > 0 ) {
            res += a[idx]
            idx -= idx and (-idx)
        }
        
        return res
        
    }
    
    fun add(i: Int, x: Long) {
        
        var idx = i+1
        while( idx <= N ) {
            a[idx] += x
            idx += idx and (-idx)
        }
        
    }
    
}

class UnionFind(N: Int) {
    
    var parent = Array<Int>(N) {it}
    var rank = Array<Int>(N) {1}
    var size = Array<Int>(N) {1}
    
    fun root(x: Int): Int {
        
        if( parent[x] == x ) {
            return x
        }else {
            parent[x] = root(parent[x])
            return parent[x]
        }
        
    }
    
    fun unite(x: Int, y: Int) {
        
        val rx = root(x)
        val ry = root(y)
        if( rx == ry ) return
        
        if( rank[rx] > rank[ry] ) {
            parent[ry] = rx
            size[rx] += size[ry]
        }else {
            parent[rx] = ry
            size[ry] += size[rx]
            if( rank[rx] == rank[ry] ) rank[ry]++
        }
        
    }
    
    fun same(x: Int, y: Int): Boolean = (root(x) == root(y))
    fun getSize(x: Int): Int = size[root(x)]
    
}

/* struct end */

/* math begin */

fun intceil(x: Double) = ceil(x).toInt()
fun intfloor(x: Double) = floor(x).toInt()
fun gcd(x: Int, y: Int): Int {
    
    var a = max(x, y)
    var b = min(x, y)
    var r: Int
    
    do {
        r = a%b
        a = b
        b = r
    }while( r > 0 )
    
    return a
    
}

/* math end */

/* I/O begin */

var st = StringTokenizer("")
val br = System.`in`.bufferedReader()
val pw = PrintWriter(System.out, false)

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()!!
fun nextDouble() = next().toDouble()
fun nextIntarr(n: Int) = Array<Int>(n) {nextInt()}
fun nextStrarr(n: Int) = Array<String>(n) {next()}
fun nextLongarr(n: Int) = Array<Long>(n) {nextLong()}

fun next(): String {
    
    if( !st.hasMoreTokens() ) st = StringTokenizer(br.readLine()!!)
    return st.nextToken()
    
}

/* I/O end */
0