Submission #1359192
Source Code Expand
package main import ( "bufio" "fmt" "log" "os" "strconv" ) func main() { log.SetFlags(log.Lshortfile) scan := newScanner() x := scan.nextInt() y := scan.nextInt() var cnt int if x > y { cnt++ x *= -1 } cnt += abs(y) - abs(x) x = abs(y) * zero(x) if x != y { cnt++ } fmt.Println(cnt) } 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 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 | 1526 Byte |
Status | WA |
Exec Time | 1 ms |
Memory | 640 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 300 | ||||||
Status |
|
|
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 | WA | 1 ms | 640 KB |
1_02.txt | WA | 1 ms | 640 KB |
1_03.txt | WA | 1 ms | 640 KB |
1_04.txt | WA | 1 ms | 640 KB |
1_05.txt | WA | 1 ms | 640 KB |
1_06.txt | AC | 1 ms | 640 KB |
1_07.txt | WA | 1 ms | 640 KB |
1_08.txt | AC | 1 ms | 640 KB |
1_09.txt | WA | 1 ms | 640 KB |
1_10.txt | WA | 1 ms | 640 KB |