AtCoder Grand Contest 008

Submission #1359224

Source codeソースコード

package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

func main() {
	log.SetFlags(log.Lshortfile)
	scan := newScanner()
	x := scan.nextInt()
	y := scan.nextInt()

	var cnt [3]int
	cnt[0] = y - x
	cnt[1] = abs(y-x) + 2
	if abs(x) == abs(y) {
		cnt[2] = 1
	} else {
		cnt[2] = math.MaxInt64
	}
	log.Println(cnt)
	for i := range cnt {
		if cnt[i] < 0 {
			cnt[i] = math.MaxInt64
		}
	}
	fmt.Println(s(cnt, min))
}

func zero(a int) int {
	if a == 0 {
		return 0
	} else if a > 0 {
		return 1
	} else {
		return -1
	}
}

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

func s(a [3]int, f func(int, int) int) int {
	r := a[0]
	for i := 1; i < len(a); i++ {
		r = f(r, a[i])
	}
	return r
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) nextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) nextInt() int {
	v, _ := strconv.Atoi(s.next())
	return v
}

func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

Submission

Task問題 A - Simple Calculator
User nameユーザ名 fmhr
Created time投稿日時
Language言語 Go (1.6)
Status状態 WA
Score得点 0
Source lengthソースコード長 1779 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_00.txt,0_01.txt,0_02.txt
All 0 / 300 0_00.txt,0_01.txt,0_02.txt,1_00.txt,1_01.txt,1_02.txt,1_03.txt,1_04.txt,1_05.txt,1_06.txt,1_07.txt,1_08.txt,1_09.txt,1_10.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_00.txt AC 1 ms 640 KB
0_01.txt AC 1 ms 640 KB
0_02.txt AC 1 ms 640 KB
1_00.txt AC 1 ms 640 KB
1_01.txt AC 1 ms 640 KB
1_02.txt WA
1_03.txt WA
1_04.txt AC 1 ms 640 KB
1_05.txt AC 1 ms 640 KB
1_06.txt WA
1_07.txt WA
1_08.txt WA
1_09.txt WA
1_10.txt AC 1 ms 640 KB