-
Notifications
You must be signed in to change notification settings - Fork 0
/
ryu-1874-timeout.go
56 lines (46 loc) · 746 Bytes
/
ryu-1874-timeout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"bytes"
"fmt"
)
func main() {
/*
https://www.acmicpc.net/problem/1874
*/
var nOrder int
_, _ = fmt.Scanln(&nOrder)
var stack [100000]int
lenStack := 0
stackNext := 1
var buf bytes.Buffer
var x int
for i := 0; i < nOrder; i++ {
_, _ = fmt.Scan(&x)
for ; ; stackNext++ {
if lenStack > 0 {
top := stack[lenStack-1]
if x == top {
lenStack--
_, _ = buf.WriteString("-\n")
break
}
if x < top {
fmt.Println("NO")
return
}
}
if stackNext > nOrder {
fmt.Println("NO")
return
}
stack[lenStack] = stackNext
lenStack++
_, _ = buf.WriteString("+\n")
}
}
if lenStack > 0 {
fmt.Println("NO")
return
}
fmt.Print(buf.String())
}