forked from EndlessCheng/codeforces-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1516C.go
50 lines (44 loc) · 737 Bytes
/
1516C.go
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
49
50
package main
import (
"bufio"
. "fmt"
"io"
"math"
)
// https://space.bilibili.com/206214
func CF1516C(_r io.Reader, out io.Writer) {
in := bufio.NewReader(_r)
var n, total, idx int
Fscan(in, &n)
a := make([]int, n)
minLowbit := math.MaxInt
for i := range a {
Fscan(in, &a[i])
total += a[i]
lb := a[i] & -a[i]
if lb < minLowbit {
minLowbit = lb
idx = i
}
}
total /= minLowbit
if total%2 > 0 {
Fprint(out, 0)
return
}
f := make([]bool, total+1)
f[0] = true
for _, x := range a {
x /= minLowbit
for j := total; j >= x; j-- {
f[j] = f[j] || f[j-x]
}
}
if f[total/2] {
Fprintln(out, 1)
Fprint(out, idx+1)
} else {
Fprint(out, 0)
}
}
//func main() { CF1516C(os.Stdin, os.Stdout) }