Submission #1359224


Source Code Expand

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 Info

Submission Time
Task A - Simple Calculator
User fmhr
Language Go (1.6)
Score 0
Code Size 1779 Byte
Status WA
Exec Time 1 ms
Memory 640 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 3
AC × 8
WA × 6
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 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
Case Name Status Exec Time Memory
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 ms 640 KB
1_03.txt WA 1 ms 640 KB
1_04.txt AC 1 ms 640 KB
1_05.txt AC 1 ms 640 KB
1_06.txt WA 1 ms 640 KB
1_07.txt WA 1 ms 640 KB
1_08.txt WA 1 ms 640 KB
1_09.txt WA 1 ms 640 KB
1_10.txt AC 1 ms 640 KB