Skip to content

Commit 4882947

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents cf576e0 + 5aabca5 commit 4882947

File tree

7 files changed

+168
-1
lines changed

7 files changed

+168
-1
lines changed

main/400-499/463B.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
func CF463B(_r io.Reader, out io.Writer) {
11+
in := bufio.NewReader(_r)
12+
var n, v, ans int
13+
for Fscan(in, &n); n > 0; n-- {
14+
if Fscan(in, &v); v > ans {
15+
ans = v
16+
}
17+
}
18+
Fprint(out, ans)
19+
}
20+
21+
//func main() { CF463B(os.Stdin, os.Stdout) }

main/400-499/463B_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/463/B
9+
// https://codeforces.com/problemset/status/463/problem/B
10+
func TestCF463B(t *testing.T) {
11+
// just copy from website
12+
rawText := `
13+
inputCopy
14+
5
15+
3 4 3 2 4
16+
outputCopy
17+
4
18+
inputCopy
19+
3
20+
4 4 4
21+
outputCopy
22+
4`
23+
testutil.AssertEqualCase(t, rawText, 0, CF463B)
24+
}

main/400-499/463D.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
func CF463D(_r io.Reader, out io.Writer) {
11+
in := bufio.NewReader(_r)
12+
max := func(a, b int) int {
13+
if b > a {
14+
return b
15+
}
16+
return a
17+
}
18+
19+
var n, m, ans int
20+
Fscan(in, &m, &n)
21+
a := make([]int, m)
22+
pos := make([][]int, n)
23+
for i := range pos {
24+
pos[i] = make([]int, m+1)
25+
for j := range a {
26+
Fscan(in, &a[j])
27+
pos[i][a[j]] = j
28+
}
29+
}
30+
31+
dp := make([]int, m) // 最长路
32+
for i, v := range a {
33+
o:
34+
for j, w := range a[:i] {
35+
for _, p := range pos {
36+
if p[w] > p[v] { // 把其中一行当作(1-n),其余行映射一下
37+
continue o
38+
}
39+
}
40+
dp[i] = max(dp[i], dp[j])
41+
}
42+
dp[i]++
43+
ans = max(ans, dp[i])
44+
}
45+
Fprint(out, ans)
46+
}
47+
48+
//func main() { CF463D(os.Stdin, os.Stdout) }

main/400-499/463D_test.go

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

main/700-799/768B.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
. "fmt"
5+
"io"
6+
"math/bits"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
func CF768B(in io.Reader, out io.Writer) {
11+
var n, l, r uint64
12+
Fscan(in, &n, &l, &r)
13+
tot := (uint64(1)<<bits.Len64(n) - 1) >> 1
14+
f := func(m uint64) (res uint64) {
15+
for n, tot := n, tot; m > 0; n >>= 1 {
16+
if m >= tot {
17+
m -= tot
18+
res += n / 2
19+
if m > 0 {
20+
m--
21+
res += n & 1
22+
}
23+
}
24+
tot >>= 1
25+
}
26+
return
27+
}
28+
Fprint(out, f(r)-f(l-1))
29+
}
30+
31+
//func main() { CF768B(os.Stdin, os.Stdout) }

main/700-799/768B_test.go

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

main/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ Compiler info: go1.15.6, windows, 386
1212

1313
例如:[1439C_test.go](./1400-1499/1439C_test.go)
1414

15-
交互题的写法要复杂一些,需要把涉及输入输出的地方抽象成接口,详见 [interactive_problem](/copypasta/template/interactive_problem)
15+
交互题的写法要复杂一些,为方便测试,需要把涉及输入输出的地方抽象成接口,详见 [interactive_problem](/copypasta/template/interactive_problem)

0 commit comments

Comments
 (0)