Skip to content

Commit fbdf8fe

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 8f70d78 + a568a92 commit fbdf8fe

30 files changed

+1015
-12
lines changed

copypasta/deque.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package copypasta
22

33
// 双端队列
4-
// 用两个 slice 拼在一起实现
4+
// 用两个 slice 头对头拼在一起实现
55
// 另一种实现是 make 个两倍大小的 slice,然后用两个下标 s t 模拟
66
// 应用见 graph.go 中的 01 最短路
77

go.mod

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
module codeforces-go
1+
module github.com/EndlessCheng/codeforces-go
22

33
go 1.17
44

55
require (
6-
github.com/EndlessCheng/codeforces-go v0.0.0-00010101000000-000000000000
76
github.com/emirpasic/gods v1.12.0
87
github.com/levigross/grequests v0.0.0-20190908174114-253788527a1a
98
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
@@ -13,13 +12,12 @@ require (
1312
)
1413

1514
require (
15+
github.com/blend/go-sdk v1.20211025.3 // indirect
1616
github.com/davecgh/go-spew v1.1.1 // indirect
1717
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
1818
github.com/google/go-querystring v1.0.0 // indirect
19-
github.com/kr/pretty v0.1.0 // indirect
2019
github.com/pmezard/go-difflib v1.0.0 // indirect
2120
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
21+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
2222
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
2323
)
24-
25-
replace github.com/EndlessCheng/codeforces-go => ./

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
4646
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
4747
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
4848
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
49-
github.com/blend/go-sdk v1.20210918.2 h1:YH7wBDTNPCFUr4W3cVVwp31LsEYFBSLriXE/oqzDxPs=
50-
github.com/blend/go-sdk v1.20210918.2/go.mod h1:nbmX7cdPm66JOqg6M3cKMtuqj6RzkE72sHZue61T5c0=
49+
github.com/blend/go-sdk v1.20211025.3 h1:3f8hYTMb9ufP8IkBtsflNohAqoKo4hEBbeR0s4bfBqI=
50+
github.com/blend/go-sdk v1.20211025.3/go.mod h1:nbmX7cdPm66JOqg6M3cKMtuqj6RzkE72sHZue61T5c0=
5151
github.com/blend/sentry-go v1.0.1/go.mod h1:hgyX3WXen2YBiA0NitlfsXsvS+9ly2YlEBmmmYDgrWY=
5252
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
5353
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=

main/1-99/25A.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
. "fmt"
5+
"io"
6+
)
7+
8+
// github.com/EndlessCheng/codeforces-go
9+
func CF25A(in io.Reader, out io.Writer) {
10+
var n, c, tar int
11+
Fscan(in, &n)
12+
a := make([]int, n)
13+
for i := range a {
14+
Fscan(in, &a[i])
15+
a[i] &= 1
16+
}
17+
for _, v := range a[:3] {
18+
c += v
19+
}
20+
if c < 2 {
21+
tar = 1
22+
}
23+
for i, v := range a {
24+
if v == tar {
25+
Fprint(out, i+1)
26+
}
27+
}
28+
}
29+
30+
//func main() { CF25A(os.Stdin, os.Stdout) }

main/1-99/25A_test.go

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

main/1000-1099/1063B.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
type pair63 struct{ x, y, l, r int }
11+
type deque63 struct{ l, r []pair63 }
12+
13+
func (q deque63) empty() bool { return len(q.l) == 0 && len(q.r) == 0 }
14+
func (q *deque63) pushL(v pair63) { q.l = append(q.l, v) }
15+
func (q *deque63) pushR(v pair63) { q.r = append(q.r, v) }
16+
func (q *deque63) popL() (v pair63) {
17+
if len(q.l) > 0 {
18+
q.l, v = q.l[:len(q.l)-1], q.l[len(q.l)-1]
19+
} else {
20+
v, q.r = q.r[0], q.r[1:]
21+
}
22+
return
23+
}
24+
25+
func CF1063B(_r io.Reader, out io.Writer) {
26+
in := bufio.NewReader(_r)
27+
dir4 := []struct{ x, y, l, r int }{{x: -1}, {x: 1}, {0, -1, 1, 0}, {0, 1, 0, 1}}
28+
29+
var n, m, sx, sy, ll, rr, ans int
30+
Fscan(in, &n, &m, &sx, &sy, &ll, &rr)
31+
sx--
32+
sy--
33+
g := make([][]byte, n)
34+
for i := range g {
35+
Fscan(in, &g[i])
36+
}
37+
38+
q := deque63{}
39+
q.pushL(pair63{sx, sy, 0, 0})
40+
g[sx][sy] = 0
41+
for !q.empty() {
42+
ans++
43+
p := q.popL()
44+
for _, d := range dir4 {
45+
x, y, l, r := p.x+d.x, p.y+d.y, p.l+d.l, p.r+d.r
46+
if 0 <= x && x < n && 0 <= y && y < m && l <= ll && r <= rr && g[x][y] == '.' {
47+
g[x][y] = 0
48+
p := pair63{x, y, l, r}
49+
if d.y == 0 {
50+
q.pushL(p)
51+
} else {
52+
q.pushR(p)
53+
}
54+
}
55+
}
56+
}
57+
Fprint(out, ans)
58+
}
59+
60+
//func main() { CF1063B(os.Stdin, os.Stdout) }

main/1000-1099/1063B_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/1063/B
9+
// https://codeforces.com/problemset/status/1063/problem/B
10+
func TestCF1063B(t *testing.T) {
11+
// just copy from website
12+
rawText := `
13+
inputCopy
14+
4 5
15+
3 2
16+
1 2
17+
.....
18+
.***.
19+
...**
20+
*....
21+
outputCopy
22+
10
23+
inputCopy
24+
4 4
25+
2 2
26+
0 1
27+
....
28+
..*.
29+
....
30+
....
31+
outputCopy
32+
7`
33+
testutil.AssertEqualCase(t, rawText, 0, CF1063B)
34+
}

main/1100-1199/1190B.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
func CF1190B(_r io.Reader, out io.Writer) {
11+
in := bufio.NewReader(_r)
12+
var n, v int
13+
Fscan(in, &n)
14+
sum := int(int64(n) * int64(n-1) / 2 & 1)
15+
cnt := make(map[int]int8, n)
16+
for dup := false; n > 0; n-- {
17+
Fscan(in, &v)
18+
if cnt[v]++; cnt[v] > 1 {
19+
if dup || v == 0 || cnt[v-1] > 0 {
20+
Fprint(out, "cslnb")
21+
return
22+
}
23+
dup = true
24+
}
25+
if cnt[v+1] > 1 {
26+
Fprint(out, "cslnb")
27+
return
28+
}
29+
sum ^= v & 1
30+
}
31+
if sum == 0 {
32+
Fprint(out, "cslnb")
33+
} else {
34+
Fprint(out, "sjfnb")
35+
}
36+
}
37+
38+
//func main() { CF1190B(os.Stdin, os.Stdout) }

main/1100-1199/1190B_test.go

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

main/1200-1299/1225D.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
func CF1225D(_r io.Reader, out io.Writer) {
11+
in := bufio.NewReader(_r)
12+
const mx int = 1e5
13+
lpf := [mx + 1]int{1: 1}
14+
for i := 2; i <= mx; i++ {
15+
if lpf[i] == 0 {
16+
for j := i; j <= mx; j += i {
17+
if lpf[j] == 0 {
18+
lpf[j] = i
19+
}
20+
}
21+
}
22+
}
23+
24+
var n, k, v int
25+
ans := int64(0)
26+
cnt := map[string]int{} // 或者用 [6]int 来代替 string,下面改成 p<<8|e 和 p<<8|(k-e)
27+
for Fscan(in, &n, &k); n > 0; n-- {
28+
s := []byte{}
29+
t := []byte{}
30+
Fscan(in, &v)
31+
for v > 1 {
32+
p, e := lpf[v], 1
33+
for v /= p; lpf[v] == p; v /= p {
34+
e++
35+
}
36+
if e %= k; e > 0 {
37+
s = append(s, byte(p>>16), byte(p>>8), byte(p), byte(e))
38+
t = append(t, byte(p>>16), byte(p>>8), byte(p), byte(k-e))
39+
}
40+
}
41+
ans += int64(cnt[string(t)])
42+
cnt[string(s)]++
43+
}
44+
Fprint(out, ans)
45+
}
46+
47+
//func main() { CF1225D(os.Stdin, os.Stdout) }

0 commit comments

Comments
 (0)