Skip to content
68 changes: 68 additions & 0 deletions src/2week/byeonghee/NBA 농구.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package `2week`.byeonghee

import java.io.*

class `소병희_NBA 농구` {
companion object {
fun getSolution() : Solution {
return Solution()
}
}

class Solution {
val br = BufferedReader(InputStreamReader(System.`in`))

data class Goal(val team: Int, val time: Int)
val goals = mutableListOf<Goal>()

val maxT = 48 * 60
val winningT = IntArray(2)
var markTeam = 0
var markTime = 0

fun timeToInt(time: String) : Int {
val (m, s) = time.split(":").map { it.first().digitToInt() * 10 + it.last().digitToInt() }
return m * 60 + s
}

fun intToTime(time: Int) : String {
val m = (time / 60).toString().padStart(2, '0')
val s = (time % 60).toString().padStart(2, '0')
return "$m:$s"
}

fun teamCount(team: Int) = if (team == 1) 1 else -1

fun solution() {
repeat(br.readLine().toInt()) {
br.readLine().split(" ").run {
goals.add(Goal(first().toInt(), timeToInt(last())))
}
}
goals.sortBy{ it.time }

for((goalTeam, goalTime) in goals) {
markTime = if (markTeam == 0) goalTime else markTime
markTeam += teamCount(goalTeam)

if(markTeam == 0) {
winningT[goalTeam % 2] += (goalTime - markTime)
markTime = goalTime
}
}

if(markTeam > 0) {
winningT[0] += (maxT - markTime)
}
else if (markTeam < 0) {
winningT[1] += (maxT - markTime)
}

println(winningT.joinToString("\n") { intToTime(it) })
}
}
}

fun main() {
`소병희_NBA 농구`.getSolution().solution()
}
78 changes: 78 additions & 0 deletions src/2week/byeonghee/그림.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package `2week`.byeonghee

/**
* @접근방법: bfs
*/

import java.io.*

class `소병희_그림` {
companion object {
fun getSolution() : Solution {
return Solution()
}
}

class Solution {

private val br = BufferedReader(InputStreamReader(System.`in`))

var n = 0
var m = 0
var canvas = Array(502){ IntArray(502) }

data class Pos(val r : Int, val c: Int)
private val adjacents = listOf(
Pos(-1, 0),
Pos(0, -1),
Pos(0, 1),
Pos(1, 0)
)

var q = ArrayDeque<Pos>()

var drawCount = 0
var drawSize = 0
var maxDrawSize = 0


fun solution() {
br.readLine().split(" ").run {
n = first().toInt()
m = last().toInt()
}
canvas = Array(n) { br.readLine().split(" ").map{ it.toInt() }.toIntArray() }

for(i in 0 until n) for(j in 0 until m) {
if (canvas[i][j] == 0) continue
canvas[i][j] = 0
drawCount++
drawSize = 1

q.addLast(Pos(i, j))
while(q.isNotEmpty()) {
q.removeFirst().run {
for((dr, dc) in adjacents) {
if (r + dr in 0 until n
&& c + dc in 0 until m
&& canvas[r + dr][c + dc] == 1
) {
drawSize++
canvas[r + dr][c + dc] = 0
q.addLast(Pos(r + dr, c + dc))
}
}
}
}
maxDrawSize = Integer.max(maxDrawSize, drawSize)
}

println(drawCount)
println(maxDrawSize)
}
}
}

fun main() {
`소병희_그림`.getSolution().solution()
}
63 changes: 63 additions & 0 deletions src/2week/byeonghee/기차가 어둠을 헤치고 은하수를.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package `2week`.byeonghee

/**
* 접근방식: 비트마스킹, distinct()
* 각 열차를 20개의 비트를 사용하는 정수로 표현하고
* 모든 명령이 끝난 후 열차를 모아놓은 IntArray에 distinct().size로 은하수를 건너는 개수를 구한다.
*/

import java.io.*

class `소병희_기차가 어둠을 헤치고 은하수를` {
companion object {
fun getSolution() : Solution {
return Solution()
}
}

class Solution {
companion object {
const val GET_ON = 1
const val GET_OFF = 2
const val MV_BACK = 3
const val MV_FORE = 4

const val masking = (1 shl 20) - 1
}

val br = BufferedReader(InputStreamReader(System.`in`))

var comm = 0
var tr = 0
var ps = 0

fun solution() {
val (N, M) = br.readLine().split(" ").map{ it.toInt() }
val trains = IntArray(N)

repeat(M) {
br.readLine().split(" ").map{ it.toInt() }.run {
comm = component1()
tr = component2()
if (size > 2) ps = component3()
}

trains[tr - 1] = trains[tr - 1].let {
when(comm) {
GET_ON -> it or (1 shl (ps - 1))
GET_OFF -> it and (masking - (1 shl (ps - 1)))
MV_BACK -> (it * 2) and masking
MV_FORE -> it / 2
else -> it
}
}
}

println(trains.distinct().size)
}
}
}

fun main() {
`소병희_기차가 어둠을 헤치고 은하수를`.getSolution().solution()
}
73 changes: 73 additions & 0 deletions src/2week/byeonghee/단지 번호 붙이기.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package `2week`.byeonghee

/**
* 접근방식: dfs
* 문제를 잘 읽자
* 반례모음 : https://www.acmicpc.net/board/view/97339
*/

import java.io.*

class `소병희_단지 번호 붙이기` {
companion object {
fun getSolution() : Solution {
return Solution()
}
}

class Solution {
companion object {
const val BLANK = '0'
const val APART = '1'
}

private val br = BufferedReader(InputStreamReader(System.`in`))

lateinit var apartMap: Array<CharArray>

var n = 0
var complexCount = 0
/** ▽▽ 이걸 IntArray(200)으로 임의로 줬었는데 아무래도 200개를 넘어갔던 것 같다 **/
private val complexList = mutableListOf<Int>()
private val around = listOf(
Pair(-1, 0),
Pair(0, -1),
Pair(0, 1),
Pair(1, 0)
)

fun solution() {
n = br.readLine().toInt()
apartMap = Array(n) { br.readLine().toCharArray() }

for(i in 0 until n) for(j in 0 until n) {
if (apartMap[i][j] == BLANK) continue

complexList.add(0)
dfs(i, j)
complexCount++
}

println(complexCount)
println(complexList.sorted().joinToString("\n"))
}

private fun dfs(r: Int, c: Int) {
apartMap[r][c] = BLANK
complexList[complexCount]++

for((dr, dc) in around) {
if ((r + dr) in 0 until n
&& (c + dc) in 0 until n
&& apartMap[r + dr][c + dc] == APART
) {
dfs(r + dr, c + dc)
}
}
}
}
}

fun main() {
`소병희_단지 번호 붙이기`.getSolution().solution()
}
37 changes: 37 additions & 0 deletions src/2week/byeonghee/보물.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package `2week`.byeonghee

/**
* @접근방법: 하나는 오름차, 하나는 내림차로 정렬
*/

import java.io.*

class `소병희_보물` {
companion object {
fun getSolution() : Solution {
return Solution()
}
}

class Solution {
private val br = BufferedReader(InputStreamReader(System.`in`))

private var N = 0
private var A = listOf<Int>()
private var B = listOf<Int>()
var answer = 0

fun solution() {
N = br.readLine().toInt()
A = br.readLine().split(" ").map{ it.toInt() }.sorted()
B = br.readLine().split(" ").map{ it.toInt() }.sortedDescending()

for(i in 0 until N) { answer += A[i] * B[i] }
println(answer)
}
}
}

fun main() {
`소병희_보물`.getSolution().solution()
}
59 changes: 59 additions & 0 deletions src/2week/byeonghee/성격 유형 검사하기.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package `2week`.byeonghee

/**
* @접근방식 : 알파벳순으로 빠른 4개를 posType, 그 반대 유형을 같은 인덱스로 negType에 저장
*
*/

class `소병희_성격 유형 검사하기` {
private val scores = IntArray(4)
private val posType = arrayOf('R', 'C', 'J', 'A')
private val negType = arrayOf('T', 'F', 'M', 'N')

private fun getType(c: Char): Int {
return when(c) {
'R', 'T' -> 0
'F', 'C' -> 1
'M', 'J' -> 2
'A', 'N' -> 3
else -> -1
}
}

private fun getTypeSign(c: Char): Int {
return when(c) {
in posType -> 1
in negType -> -1
else -> 0
}
}

private fun getPoint(i: Int) : Int {
return if (i > 4) i - 4 else 4 - i
}

private fun getPointSign(i : Int): Int {
return if (i < 4) 1
else if (i > 4) -1
else 0
}

fun solution(surveys: Array<String>, choices: IntArray): String {
for(i in surveys.indices) {
val c = surveys[i].first()
val op = choices[i]

scores[getType(c)] += getTypeSign(c) * getPointSign(op) * getPoint(op)
}

val sb = StringBuilder()
for(i in 0 until 4) {
sb.append(
if (scores[i] >= 0) posType[i]
else negType[i]
)
}

return sb.toString()
}
}
Loading