Submission #5436891


Source Code Expand

package main

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

func main() {
  var n,m int = NextInts()
  var x []int = NextIntArray()
  sort.Ints(x)
  var r []map[int]int = make([]map[int]int,m)
  for i:=0;i<m;i++ { r[i] = map[int]int{} }
  for i:=0;i<n;i++ { r[x[i]%m][x[i]]++ }
  var p int
  for _,v := range r[0] { p += v }
  p /= 2
  for i:=1;i<=m/2;i++ {
    var t0all,t0even,t1all,t1even int
    for _,v := range r[i] {
      t0all += v
      t0even += (v/2)*2
    }
    for _,v := range r[m-i] {
      t1all += v
      t1even += (v/2)*2
    }
    if i == m-i {
      p += t0all/2
      continue
    }
    if t0all == t1all {
      p += t0all
      continue
    }
    if t0all > t1all {
      t0all,t1all = t1all,t0all
      t0even,t1even = t1even,t0even
    }
    var t0 int = t0all
    if t1all-t0all <= t1even {
      t0 += (t1all-t0all)/2
    } else {
      t0 += t1even/2
    }
    var t1 int = t1all-t1even
    if t1 > t0all { t1 = t0all }
    t1 += t1even/2
    var t2 int = t0all-t0even
    if t2 > t1all-t1even { t2 = t1all-t1even }
    t2 += (t0even+t1even)/2
    p += max(t0,t1,t2)
  }
  fmt.Println(p)
}

func max(n ...int) int {
  m := n[0]
  for i:=1;i<len(n);i++ {
    if m < n[i] { m = n[i] }
  }
  return m
}

var reader = bufio.NewReaderSize(os.Stdin,1000000)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInts() (int,int) {
  var x,y int
  var s []string = strings.Split(NextLine()," ")
  x,_ = strconv.Atoi(s[0])
  y,_ = strconv.Atoi(s[1])
  return x,y
}
func NextIntArray() []int {
  var s []string = strings.Split(NextLine()," ")
  var n int = len(s)
  var a []int = make([]int,n)
  for i:=0;i<n;i++ {
    a[i],_ = strconv.Atoi(s[i])
  }
  return a
}

Submission Info

Submission Time
Task D - Pair Cards
User ue1221
Language Go (1.6)
Score 700
Code Size 2011 Byte
Status AC
Exec Time 103 ms
Memory 27904 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 34
Set Name Test Cases
sample sample-01.txt, sample-02.txt
all sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
01-01.txt AC 1 ms 640 KB
01-02.txt AC 53 ms 9728 KB
01-03.txt AC 54 ms 8448 KB
01-04.txt AC 51 ms 7808 KB
01-05.txt AC 53 ms 8320 KB
01-06.txt AC 64 ms 7808 KB
01-07.txt AC 52 ms 7680 KB
01-08.txt AC 59 ms 7680 KB
01-09.txt AC 54 ms 7808 KB
01-10.txt AC 64 ms 10880 KB
01-11.txt AC 99 ms 20096 KB
01-12.txt AC 18 ms 4864 KB
01-13.txt AC 24 ms 6784 KB
01-14.txt AC 56 ms 8960 KB
01-15.txt AC 65 ms 8320 KB
01-16.txt AC 59 ms 8704 KB
01-17.txt AC 55 ms 7808 KB
01-18.txt AC 68 ms 8960 KB
01-19.txt AC 51 ms 7552 KB
01-20.txt AC 103 ms 27904 KB
01-21.txt AC 37 ms 4736 KB
01-22.txt AC 37 ms 4864 KB
01-23.txt AC 36 ms 4736 KB
01-24.txt AC 35 ms 4736 KB
01-25.txt AC 39 ms 6656 KB
01-26.txt AC 52 ms 8576 KB
01-27.txt AC 62 ms 17024 KB
01-28.txt AC 23 ms 7040 KB
01-29.txt AC 7 ms 3072 KB
01-30.txt AC 23 ms 6400 KB
sample-01.txt AC 1 ms 640 KB
sample-02.txt AC 1 ms 640 KB