-
Notifications
You must be signed in to change notification settings - Fork 1
/
abc008_c.kt
48 lines (46 loc) · 1.25 KB
/
abc008_c.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// this model would be TLE...
// another way is to use mathematical way
val side:MutableList<MutableList<Int>> = mutableListOf( )
fun perm(depth: Int, input: List<Int>, buff: MutableList<Int> ) {
if( depth == 0)
side.add( buff )
for(i in (0..input.size-1)) {
when {
buff.contains(i) == false -> {
val nextBuff = buff.toMutableList()
nextBuff.add(i)
perm(depth-1, input, nextBuff)
}
else -> null
}
}
}
data class ST(val param: Int, var st: Boolean)
fun main( args : Array<String> ) {
val n = readLine()!!.toInt()
val inputs = (1..n).map {
readLine()!!.toInt()
}
perm(inputs.size, inputs, mutableListOf<Int>() )
//println(side)
side.map { sd ->
val qu = sd.map { i -> ST(inputs[i], true) }
.toMutableList()
.let { x ->
(0..x.size-2).map { i ->
(i+1..x.size-1).map { k ->
when {
x[k].param%x[i].param == 0 && x[k].st == true -> x[k].st = false
x[k].param%x[i].param == 0 && x[k].st == false -> x[k].st = true
else -> null
}
}
}
//println(x)
x
}
qu
}.let {
( it.flatMap { it }.count { it.st == true }.toDouble() / it.size ).let { println(it) }
}
}