-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0016.kt
39 lines (37 loc) · 911 Bytes
/
0016.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
fun main( args : Array<String> ) {
val (x, n) = readLine()!!.split(" ").map { it.toInt() }
val ax = readLine()!!.split(" ").map { it.toInt() }.sortedBy { it }
val max = ax.max()!!
val mm = mutableMapOf<Int, Long>(0 to 1L, 1 to x.toLong())
val L = 1000_003L
var bya = 1
loop@ while (true) {
bya *= 2
mm[bya] = mm[bya/2]!! * mm[bya/2]!! % L
if( bya > max ) break@loop
}
// build dataset
val cs = mutableListOf<MutableList<Pair<Int,Long>>>()
for( a in ax.reversed() ) {
var b = a
val bs = mutableListOf<Pair<Int, Long>>()
mm.toList().sortedBy { it.first * -1 }.map {
if( b - it.first > 0 ) {
bs.add( it )
b -= it.first
}
}
println( a )
println( bs )
cs.add( bs )
}
cs.map { bs ->
var acc = 1L
for( b in bs ) {
acc *= b.second
}
acc
}.reduce { y,x ->
y+x
}.let { println( it % L ) }
}