Skip to content

Commit

Permalink
CF1926F
Browse files Browse the repository at this point in the history
  • Loading branch information
EndlessCheng committed Feb 20, 2024
1 parent eeebcad commit 017250f
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions main/1900-1999/1926F.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ func cf1926F(_r io.Reader, out io.Writer) {
var T int
var s string
const N = 7
const MASK = 1<<(N-2) - 1
a := [N]int{}
dp := [N][1 << N][1 << (N - 2)]int{}
for Fscan(in, &T); T > 0; T-- {
Expand Down Expand Up @@ -41,23 +40,11 @@ func cf1926F(_r io.Reader, out io.Writer) {
return *p
}
res := N * N
o:
for cur, ok := a[i], true; ok; ok = cur != a[i] {
for t, lb := pre5, 0; t > 0; t ^= lb {
lb = t & -t
if cur&lb > 0 && cur&(lb<<2) > 0 {
cur = (cur - 1) & a[i]
continue o
}
if cur>>2&cur&pre5 == 0 {
cur5 := pre7 >> 2 & pre7 & (cur >> 1)
res = min(res, f(i+1, cur, cur5)+bits.OnesCount(uint(cur^a[i])))
}
cur5 := 0
for t, lb := cur>>1&MASK, 0; t > 0; t ^= lb {
lb = t & -t
if pre7&lb > 0 && pre7&(lb<<2) > 0 {
cur5 |= lb
}
}
res = min(res, f(i+1, cur, cur5)+bits.OnesCount(uint(cur^a[i])))
cur = (cur - 1) & a[i]
}
*p = res
Expand Down

0 comments on commit 017250f

Please sign in to comment.