File tree Expand file tree Collapse file tree 2 files changed +82
-0
lines changed Expand file tree Collapse file tree 2 files changed +82
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "bufio"
5
+ "bytes"
6
+ . "fmt"
7
+ "io"
8
+ )
9
+
10
+ // github.com/EndlessCheng/codeforces-go
11
+ func CF1450D (_r io.Reader , _w io.Writer ) {
12
+ in := bufio .NewReader (_r )
13
+ out := bufio .NewWriter (_w )
14
+ defer out .Flush ()
15
+
16
+ var T , n int
17
+ for Fscan (in , & T ); T > 0 ; T -- {
18
+ Fscan (in , & n )
19
+ a := make ([]int , n )
20
+ c := make ([]int , n )
21
+ ans := bytes .Repeat ([]byte {'0' }, n )
22
+ ans [0 ] = '1'
23
+ for i := range a {
24
+ Fscan (in , & a [i ])
25
+ a [i ]--
26
+ c [a [i ]]++
27
+ if c [a [i ]] > 1 {
28
+ ans [0 ] = '0'
29
+ }
30
+ }
31
+ l , r := 0 , n - 1
32
+ for i , c := range c {
33
+ if c == 0 {
34
+ break
35
+ }
36
+ ans [n - 1 - i ] = '1'
37
+ if c > 1 || a [l ] != i && a [r ] != i {
38
+ break
39
+ }
40
+ if a [l ] == i {
41
+ l ++
42
+ } else {
43
+ r --
44
+ }
45
+ }
46
+ Fprintf (out , "%s\n " , ans )
47
+ }
48
+ }
49
+
50
+ //func main() { CF1450D(os.Stdin, os.Stdout) }
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "github.com/EndlessCheng/codeforces-go/main/testutil"
5
+ "testing"
6
+ )
7
+
8
+ // https://codeforces.com/problemset/problem/1450/D
9
+ // https://codeforces.com/problemset/status/1450/problem/D
10
+ func TestCF1450D (t * testing.T ) {
11
+ // just copy from website
12
+ rawText := `
13
+ inputCopy
14
+ 5
15
+ 5
16
+ 1 5 3 4 2
17
+ 4
18
+ 1 3 2 1
19
+ 5
20
+ 1 3 3 3 2
21
+ 10
22
+ 1 2 3 4 5 6 7 8 9 10
23
+ 3
24
+ 3 3 2
25
+ outputCopy
26
+ 10111
27
+ 0001
28
+ 00111
29
+ 1111111111
30
+ 000`
31
+ testutil .AssertEqualCase (t , rawText , 0 , CF1450D )
32
+ }
You can’t perform that action at this time.
0 commit comments