시배's Android
Algorithm | 백준 Kotlin 3273 두 수의 합 본문
3273번: 두 수의 합
n개의 서로 다른 양의 정수 a1, a2, ..., an으로 이루어진 수열이 있다. ai의 값은 1보다 크거나 같고, 1000000보다 작거나 같은 자연수이다. 자연수 x가 주어졌을 때, ai + aj = x (1 ≤ i < j ≤ n)을 만족하는
www.acmicpc.net
private fun main() {
val n = readLine()!!.toInt()
val a = readLine()!!.split(" ").map{ it.toInt() }
val x = readLine()!!.toInt()
val f = a.groupBy{ it }.map{ (a, b) -> a to b.size }.toMap()
println(f.map{ (y, c) -> c.toLong() * f.getOrElse(x - y) { 0 } }.sum() / 2)
}
'Algorithm' 카테고리의 다른 글
Algorithm | 백준 Kotlin 12101 1,2,3 더하기 2 (0) | 2023.10.07 |
---|---|
Algorithm | 백준 Kotlin 5548 행성 탐사 (0) | 2023.10.07 |
Algorithm | 백준 Kotlin 6443 애너그램 (0) | 2023.09.23 |
Algorithm | 백준 Kotlin 2553 마지막 팩토리얼 수 (0) | 2023.09.23 |
Algorithm | 백준 Kotlin 1158 요세푸스 문제 (0) | 2023.09.23 |