Skip to content

Commit dcf2ee8

Browse files
committed
CF962B
1 parent fbdf8fe commit dcf2ee8

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

main/900-999/962B.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
"strings"
8+
)
9+
10+
// github.com/EndlessCheng/codeforces-go
11+
func CF962B(in io.Reader, out io.Writer) {
12+
var a, b int
13+
var s string
14+
Fscan(bufio.NewReader(in), &a, &a, &b, &s)
15+
ans := a + b
16+
for _, s := range strings.FieldsFunc(s, func(r rune) bool { return r == '*' }) {
17+
n := len(s)
18+
if a < b {
19+
a, b = b, a
20+
}
21+
a -= (n + 1) / 2
22+
if a < 0 {
23+
a = 0
24+
}
25+
b -= n / 2
26+
if b < 0 {
27+
b = 0
28+
}
29+
}
30+
Fprint(out, ans-a-b)
31+
}
32+
33+
//func main() { CF962B(os.Stdin, os.Stdout) }

main/900-999/962B_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"github.com/EndlessCheng/codeforces-go/main/testutil"
5+
"testing"
6+
)
7+
8+
// https://codeforces.com/problemset/problem/962/B
9+
// https://codeforces.com/problemset/status/962/problem/B
10+
func TestCF962B(t *testing.T) {
11+
// just copy from website
12+
rawText := `
13+
inputCopy
14+
5 1 1
15+
*...*
16+
outputCopy
17+
2
18+
inputCopy
19+
6 2 3
20+
*...*.
21+
outputCopy
22+
4
23+
inputCopy
24+
11 3 10
25+
.*....**.*.
26+
outputCopy
27+
7
28+
inputCopy
29+
3 2 3
30+
***
31+
outputCopy
32+
0`
33+
testutil.AssertEqualCase(t, rawText, 0, CF962B)
34+
}

0 commit comments

Comments
 (0)