Submission #29541677
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
"strings"
)
const BUFSIZE = 10000000
var rdr *bufio.Reader
func main() {
// BUFSIZEは大きなint値を指定しておく
rdr = bufio.NewReaderSize(os.Stdin, BUFSIZE)
solve()
}
// 一行をstringで読み込み
func readline() string {
buf := make([]byte, 0, 16)
for {
l, p, e := rdr.ReadLine()
if e != nil {
fmt.Println(e.Error())
panic(e)
}
buf = append(buf, l...)
if !p {
break
}
}
return string(buf)
}
// 一行を[]intで読み込み
func readIntSlice() []int {
slice := make([]int, 0)
lines := strings.Split(readline(), " ")
for _, v := range lines {
// s2iはstringをintに変換する関数(後述)
slice = append(slice, s2i(v))
}
return slice
}
// s2iはstringをintに変換する関数(後述)
func readint() int {
return s2i(readline())
}
func readint2() (int, int) {
lines := strings.Split(readline(), " ")
return s2i(lines[0]), s2i(lines[1])
}
func readint3() (int, int, int) {
lines := strings.Split(readline(), " ")
return s2i(lines[0]), s2i(lines[1]), s2i(lines[2])
}
func readint4() (int, int, int, int) {
lines := strings.Split(readline(), " ")
return s2i(lines[0]), s2i(lines[1]), s2i(lines[2]), s2i(lines[3])
}
// string <-> int
func s2i(s string) int {
v, ok := strconv.Atoi(s)
if ok != nil {
panic("Faild : " + s + " can't convert to int")
}
return v
}
func i2s(i int) string {
return strconv.Itoa(i)
}
// bool <-> int
func b2i(b bool) int {
if b {
return 1
}
return 0
}
func i2b(i int) bool {
return i != 0
}
func min(values ...int) int {
ret := values[0]
for _, v := range values {
if ret > v {
ret = v
}
}
return ret
}
func max(values ...int) int {
ret := values[0]
for _, v := range values {
if ret < v {
ret = v
}
}
return ret
}
func is_prime(n int) bool {
switch {
case n < 2:
return false
case n == 2 || n == 3 || n == 5:
return true
case n&1 == 0:
return false
case n%2 == 0 || n%3 == 0 || n%5 == 0:
return false
}
f := true
v := 7
m := int(math.Pow(float64(n), 0.5)) + 1
for v < m {
if n%v == 0 {
return false
}
if f {
v += 4
} else {
v += 2
}
f = !f
}
return true
}
func solve() {
n := readint()
arr := readIntSlice()
stack := make([][]int, 0)
currentSub := 0
for i := 0; i < n; i++ {
v := arr[i]
if i == 0 {
fmt.Println(1)
stack = append(stack, []int{v, 1})
continue
}
if len(stack) == 0 {
fmt.Println(1)
stack = append(stack, []int{v, 1})
continue
}
lastStack := stack[len(stack)-1]
if lastStack[0] != v {
stack = append(stack, []int{v, 1})
fmt.Println(i + 1 - currentSub)
continue
}
//lastStack[0] == v
if lastStack[1]+1 != v {
stack[len(stack)-1][1] = lastStack[1] + 1
fmt.Println(i + 1 - currentSub)
continue
}
if lastStack[1]+1 == v {
currentSub += lastStack[1] + 1
fmt.Println(i + 1 - currentSub)
stack = stack[:len(stack)-1]
}
}
}
Submission Info
Submission Time |
|
Task |
D - Strange Balls |
User |
villa_ak99 |
Language |
Go (1.14.1) |
Score |
400 |
Code Size |
3149 Byte |
Status |
AC |
Exec Time |
339 ms |
Memory |
20308 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example_00.txt, example_01.txt |
All |
example_00.txt, example_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt |
Case Name |
Status |
Exec Time |
Memory |
example_00.txt |
AC |
7 ms |
2172 KB |
example_01.txt |
AC |
2 ms |
2176 KB |
test_00.txt |
AC |
339 ms |
19616 KB |
test_01.txt |
AC |
336 ms |
19592 KB |
test_02.txt |
AC |
6 ms |
2168 KB |
test_03.txt |
AC |
336 ms |
20284 KB |
test_04.txt |
AC |
332 ms |
20308 KB |
test_05.txt |
AC |
334 ms |
20248 KB |
test_06.txt |
AC |
331 ms |
17060 KB |
test_07.txt |
AC |
336 ms |
20268 KB |
test_08.txt |
AC |
329 ms |
15740 KB |
test_09.txt |
AC |
328 ms |
17660 KB |
test_10.txt |
AC |
328 ms |
17648 KB |
test_11.txt |
AC |
330 ms |
17632 KB |
test_12.txt |
AC |
334 ms |
17648 KB |
test_13.txt |
AC |
330 ms |
17432 KB |
test_14.txt |
AC |
328 ms |
17468 KB |
test_15.txt |
AC |
329 ms |
17448 KB |
test_16.txt |
AC |
332 ms |
17428 KB |
test_17.txt |
AC |
329 ms |
17448 KB |
test_18.txt |
AC |
333 ms |
19124 KB |
test_19.txt |
AC |
332 ms |
19592 KB |