AtCoder Beginner Contest 019

Submission #3013808

Source codeソースコード

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	INF = (1 << 32) - 1
)

func main() {
	s := strv()
	list := make([]string, 0)
	list = rec(s, list)
	ans := func() (res string) {
		for _, val := range list {
			res += val
		}
		return res
	}()
	fmt.Println(ans)
}

func rec(s string, l []string) []string {
	if len(s) == 0 {
		return l
	}
	cnt := 0
	for i := 0; i < len(s); i++ {
		for j := i; j < len(s); j++ {
			if s[i] == s[j] {
				cnt++
			} else {
				l = append(l, string(s[i])+strconv.Itoa(cnt))
				return rec(s[j:], l)
			}
		}
		return append(l, string(s[i])+strconv.Itoa(cnt))
	}
	return []string{}
}

/* template functions */

func readln() string {
	buf := make([]byte, 0)
	for {
		line, prefix, err := in.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if prefix == false {
			break
		}
	}
	return string(buf)
}

func strv() string {
	return strs()[0]
}

func strs() []string {
	line := strings.Split(readln(), " ")
	return line
}

func intv() int {
	return ints()[0]
}

func ints() []int {
	line := strs()
	slice := make([]int, 0)
	for _, tmp := range line {
		val, err := strconv.Atoi(tmp)
		if err != nil {
			panic(err)
		}
		slice = append(slice, val)
	}
	return slice
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func min(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func var_dump(value ...interface{}) {
	for _, v := range value {
		fmt.Printf("%#v¥n", v)
	}
}

Submission

Task問題 B - 高橋くんと文字列圧縮
User nameユーザ名 oysuake
Created time投稿日時
Language言語 Go (1.6)
Status状態 AC
Score得点 100
Source lengthソースコード長 1743 Byte
File nameファイル名
Exec time実行時間 3 ms
Memory usageメモリ使用量 1920 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - subtask0_1.txt,subtask0_2.txt,subtask0_3.txt
All 100 / 100 0.txt,1.txt,10.txt,11.txt,12.txt,13.txt,14.txt,15.txt,16.txt,17.txt,18.txt,19.txt,2.txt,20.txt,21.txt,22.txt,23.txt,24.txt,25.txt,26.txt,27.txt,28.txt,29.txt,3.txt,4.txt,5.txt,6.txt,7.txt,8.txt,9.txt,subtask0_1.txt,subtask0_2.txt,subtask0_3.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0.txt AC 2 ms 1920 KB
1.txt AC 2 ms 1920 KB
10.txt AC 1 ms 640 KB
11.txt AC 1 ms 768 KB
12.txt AC 1 ms 768 KB
13.txt AC 1 ms 768 KB
14.txt AC 1 ms 640 KB
15.txt AC 1 ms 640 KB
16.txt AC 1 ms 640 KB
17.txt AC 1 ms 640 KB
18.txt AC 1 ms 640 KB
19.txt AC 1 ms 768 KB
2.txt AC 3 ms 1920 KB
20.txt AC 1 ms 640 KB
21.txt AC 1 ms 640 KB
22.txt AC 1 ms 640 KB
23.txt AC 1 ms 640 KB
24.txt AC 1 ms 640 KB
25.txt AC 1 ms 640 KB
26.txt AC 1 ms 640 KB
27.txt AC 1 ms 640 KB
28.txt AC 1 ms 640 KB
29.txt AC 1 ms 640 KB
3.txt AC 2 ms 1920 KB
4.txt AC 3 ms 1920 KB
5.txt AC 3 ms 1920 KB
6.txt AC 2 ms 1920 KB
7.txt AC 3 ms 1920 KB
8.txt AC 3 ms 1920 KB
9.txt AC 2 ms 1920 KB
subtask0_1.txt AC 1 ms 640 KB
subtask0_2.txt AC 1 ms 640 KB
subtask0_3.txt AC 1 ms 640 KB