[GO] Keyence Programming Contest 2021 Notes

Preface

I tried Atcoder, so it's a memo for myself. I plan to add and correct it later.

problem

https://atcoder.jp/contests/keyence2021

A

Q_A.go


package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int64 {
    sc.Scan()
    i, e := strconv.ParseInt(sc.Text(),10,64)
    if e != nil {
        panic(e)
    }
    return i
}

func main() {
    sc.Split(bufio.ScanWords)

    var N int
    fmt.Scanf("%d", &N)

    var a int64
    var c int64
    b := make([]int64, N)
    d := make([]int64, N)

    a = nextInt()
    d[0] = a
    for i:=1; i<N; i++ {
        a = nextInt()
        if d[i-1] > a{
            d[i] = d[i-1]
        } else {
            d[i] = a
        }
    }

    for i:=0; i<N; i++ {
        b[i] = nextInt()
    }

    c = d[0] * b[0]
    fmt.Printf("%d\n", c)

    for i:=1; i<N; i++{

        if d[i] * b[i] > c{
            c = d[i] * b[i]
        } else {
            c = c
        }
        fmt.Printf("%d\n", c)
    }
}

B

Q_B.go


package main
 
import (
  "bufio"
  "fmt"
  "sort"
  "os"
  "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int64 {
  sc.Scan()
  i, e := strconv.ParseInt(sc.Text(),10,64)
  if e != nil {
      panic(e)
  }
  return i
}

func main() {
  sc.Split(bufio.ScanWords)

  var N, K int
  fmt.Scanf("%d %d", &N, &K)

  a := make([]int64, N)
  box := make([]int64, K)

  for i:=0; i<N; i++{
    a[i] = nextInt()
  }

  sort.Slice(a, func(i, j int) bool {
    return a[i] < a[j]
  })

  var j int = 0
  var tmp int64 = -1

  for i:=0; i<N; i++{
    if a[i] == tmp{
      if box[j] == a[i]{
        box[j] = a[i]+1
      }
      if j+1 < K{
        j = j+1
      }
    } else {
      if box[0] == a[i]{
        box[0] = a[i]+1
      }
      tmp = a[i]
      if 1 < K{
        j = 1
      }
    }
  }

  var sum int64
  for i:=0; i<K; i++{
    sum += box[i]
  }

  fmt.Printf("%d\n", sum)
}

C If you remember, I will write it later.

D If you remember, I will write it later.

E If you remember, I will write it later.

F If you remember, I will write it later.

Recommended Posts

Keyence Programming Contest 2021 Notes
Keyence Programming Contest 2020 Review
Notes for HHKB Programming Contest 2020
AtCoder Keyence Programming Contest 2020 Participation Report
Acing Programming Contest 2020
HHKB Programming Contest 2020
After "Diverta 2019 Programming Contest"
NOMURA Programming Contest 2020 Review
HHKB Programming Contest 2020 Review
Atcoder Acing Programming Contest Python
Tokio Marine & Nichido Programming Contest 2020 Review
AtCoder HHKB Programming Contest 2020 Participation Report
AtCoder Acing Programming Contest 2020 Participation Report
AtCoder Panasonic Programming Contest 2020 Participation Report
Sumitomo Mitsui Trust Bank Programming Contest 2019 Review