I tried Atcoder, so it's a memo for myself. I plan to add and correct it later.
https://atcoder.jp/contests/abc182
A
Q_A.go
package main
import (
"fmt"
)
func main() {
var A, B int
fmt.Scanf("%d %d", &A, &B)
ans := 2 * A + 100 - B
fmt.Printf("%d\n", ans)
}
B
Q_B.go
package main
import (
"fmt"
)
func main() {
var N int
fmt.Scanf("%d", &N)
A := make([]int, N)
var max int = 2
for i := 0; i < N; i++ {
fmt.Scanf("%d", &A[i])
if max < A[i]{
max = A[i]
}
}
var count, gcd, ans int
for i := 2; i<= max; i++ {
count = 0
for j:=0; j<N; j++{
if A[j] % i == 0{
count +=1
}
}
if count >= gcd {
ans = i
gcd = count
}
}
fmt.Printf("%d\n", ans)
}
C
Q_C.go
package main
import (
"fmt"
"strings"
"strconv"
)
func main() {
var N string
fmt.Scanf("%s", &N)
arr := strings.Split(N, "")
var sum, one, two int = 0, 0, 0
for i:=0; i<len(arr); i++{
var num int
num, _ = strconv.Atoi(arr[i])
div := num % 3
if div == 1{
one +=1
}else if div == 2{
two += 1
}
sum += div
}
sum = sum % 3
var ans int = -1
if sum == 0{
ans = 0
}else if sum == 1{
if one > 0 && len(arr)>1{
ans = 1
}else if two > 1 && len(arr)>2{
ans = 2
}
}else if sum == 2{
if two > 0 && len(arr)>1{
ans = 1
}else if one > 1 && len(arr)>2{
ans = 2
}
}
fmt.Printf("%d\n", ans)
}
D
Q_D.go
package main
import (
"fmt"
)
func main() {
var N int
fmt.Scanf("%d", &N)
var ans int =0
var max_right int = 0
var p_now int = 0
var total int = 0
var num int
for i:=0; i<N; i++{
fmt.Scanf("%d", &num)
total = total + num
if max_right < total {
max_right = total
}
if ans < p_now + max_right {
ans = p_now + max_right
}
p_now = p_now + total
}
fmt.Printf("%d\n", ans)
}
E If you remember, I will write it later.
F If you remember, I will write it later.
Recommended Posts