[GO] AtCoder Beginner Contest 188 Note

Preface

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

problem

https://atcoder.jp/contests/abc188

A

Q_A.go


package main

import (
    "fmt"
)

func main() {
    var X, Y int
    fmt.Scanf("%d %d", &X, &Y)

    var flag bool = false
    if X>Y{
        if X-Y < 3{
            flag = true
        }
    } else {
        if Y-X < 3{
            flag = true
        }
    }

    if flag{
        fmt.Printf("Yes\n")
    } else {
        fmt.Printf("No\n")
    }
}

B

Q_B.go


package main

import (
	"fmt"
)

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

	var sum int64 = 0
	A := make([]int64, N)
	B := make([]int64, N)

	for i:=0; i<N; i++{
		fmt.Scanf("%d", &A[i])
	}

	for i:=0; i<N; i++{
		fmt.Scanf("%d", &B[i])
	}

	for i:=0; i<N; i++{
		sum += A[i] * B[i]
	}

	if sum == 0{
		fmt.Printf("Yes\n")
	} else {
		fmt.Printf("No\n")
	}
	
}

C

Q_C.go


package main

import (
	"fmt"
)

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

	var imax int = 1 
	for i:=0; i<N; i++{
		imax *= 2
	}

	A := make([]int64, imax)

	for i:=0; i<imax; i++{
		fmt.Scanf("%d", &A[i])		
	}

	var left int64 = 0
	var left_index int 
	for i:=0; i<imax/2; i++{
		if left < A[i]{
			left = A[i]
			left_index = i
		}
	}

	var right int64 = 0
	var right_index int 
	for i:=imax/2; i<imax; i++{
		if right < A[i]{
			right = A[i]
			right_index = i
		}
	}

	if left > right{
		fmt.Printf("%d\n", right_index+1)
	} else {
		fmt.Printf("%d\n", left_index+1)
	}
	
}

D

Q_D.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 int64
    var C int64
    N = nextInt()
    C = nextInt()

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

    var amin int64 = 1000000000
    var bmax int64 = 1
    var i int64
    for i=0; i<N; i++ {

        a[i] = nextInt()
        b[i] = nextInt()
        c[i] = nextInt()

        if amin > a[i]{
            amin = a[i]
        }
        if bmax < b[i]{
            bmax = b[i]
        }
    }

    index := make(map[int64]int64)
    for i=0; i<N; i++{
        index[a[i]] = index[a[i]] + c[i]
        index[b[i]+1] = index[b[i]+1] - c[i] 
    }

    keys := make([]int64, 0, len(index))
    for k := range index {
		keys = append(keys, k)
    }
    sort.Slice(keys, func(s, t int) bool {
        return keys[s] < keys[t]
    })

    var cost_sum int64 = 0
    var sum int64 = 0
    var before int64 = 0
    for i:=0; i<len(index); i++{
        //Add to the front
        if cost_sum > C{
            sum += C * (keys[i] - before)
        } else {
            sum += cost_sum * (keys[i] - before)
        }

        // tugiwo keisann 
        cost_sum = cost_sum + index[keys[i]]
        before = keys[i]
    }

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

E If you remember, I will write it later.

F If you remember, I will write it later.

Recommended Posts

AtCoder Beginner Contest 181 Note
AtCoder Beginner Contest 187 Note
AtCoder Beginner Contest 180 Note
AtCoder Beginner Contest 182 Note
AtCoder Beginner Contest 183 Note
AtCoder Beginner Contest 184 Note
AtCoder Beginner Contest 188 Note
AtCoder Beginner Contest # 003 Participation Note
AtCoder Beginner Contest 177
AtCoder Beginner Contest 179
AtCoder Beginner Contest 172
AtCoder Beginner Contest 180
AtCoder Beginner Contest 173
Atcoder Beginner Contest 153
AtCoder Beginner Contest 152 Review
AtCoder Beginner Contest 160 Review
AtCoder Beginner Contest 178 Review
ACL Beginner Contest Note
AtCoder Beginner Contest 166 Review
AtCoder Beginner Contest 167 Review
AtCoder Regular Contest 106 Note
AtCoder Beginner Contest 169 Review
AtCoder Beginner Contest 181 Review
AtCoder Beginner Contest 171 Review
AtCoder Beginner Contest 182 Review
AtCoder Beginner Contest 180 Review
AtCoder Beginner Contest 156 WriteUp
AtCoder Beginner Contest 177 Review
AtCoder Beginner Contest 168 Review
AtCoder Beginner Contest 179 Review
Solve AtCoder Beginner Contest 100-102
AtCoder Beginner Contest 167 Memorandum
AtCoder Beginner Contest 172 Review
AtCoder Beginner Contest 176 Review
AtCoder Beginner Contest 174 Review
AtCoder Beginner Contest 153 Review
AtCoder Beginner Contest 161 Review
AtCoder Beginner Contest 170 Review
AtCoder Beginner Contest 165 Review
AtCoder Beginner Contest 173 Review
AtCoder Beginner Contest 155 Review
AtCoder Beginner Contest 162 Review
AtCoder Beginner Contest 181 Participation Report
AtCoder Beginner Contest 175 Virtual entry
AtCoder Beginner Contest 161 Participation Report
AtCoder Beginner Contest 151 Participation Report
AtCoder Beginner Contest 176 Participation Report
AtCoder Beginner Contest 154 Participation Report
AtCoder Beginner Contest 166 Participation Report
AtCoder Beginner Contest 153 Participation Report
AtCoder Beginner Contest # 002 C Problem
AtCoder Beginner Contest 145 Participation Report
AtCoder Beginner Contest 184 Participation Report
AtCoder Beginner Contest 165 Participation Report
AtCoder Beginner Contest 169 Participation Report
AtCoder Beginner Contest 178 Participation Report
AtCoder Beginner Contest 163 Participation Report
AtCoder Beginner Contest 159 Participation Report
AtCoder Beginner Contest 164 Participation Report
AtCoder Beginner Contest 168 Participation Report
AtCoder Beginner Contest 150 Participation Report