Skip to content

Commit 588b20d

Browse files
committed
CF1607E
1 parent f7ec6c3 commit 588b20d

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

main/1600-1699/1607E.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+
"bufio"
5+
. "fmt"
6+
"io"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
func CF1607E(_r io.Reader, _w io.Writer) {
11+
in := bufio.NewReader(_r)
12+
out := bufio.NewWriter(_w)
13+
defer out.Flush()
14+
dir4 := []struct{ x, y int }{'L': {-1, 0}, 'R': {1, 0}, 'D': {0, -1}, 'U': {0, 1}}
15+
16+
var T, n, m int
17+
var s string
18+
for Fscan(in, &T); T > 0; T-- {
19+
Fscan(in, &n, &m, &s)
20+
var x, y, l, r, d, u int
21+
ansX, ansY := 1, 1
22+
for _, b := range s {
23+
x += dir4[b].x
24+
y += dir4[b].y
25+
if x < l {
26+
l = x
27+
} else if x > r {
28+
r = x
29+
}
30+
if y < d {
31+
d = y
32+
} else if y > u {
33+
u = y
34+
}
35+
if r-l >= m || u-d >= n {
36+
break
37+
}
38+
ansX, ansY = 1+u, 1-l
39+
}
40+
Fprintln(out, ansX, ansY)
41+
}
42+
}
43+
44+
//func main() { CF1607E(os.Stdin, os.Stdout) }

main/1600-1699/1607E_test.go

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

0 commit comments

Comments
 (0)