-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 19-wkdghdwns199
- Loading branch information
Showing
18 changed files
with
440 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
|
||
const val MAX = 987_654_321 | ||
val colors = 1..3 | ||
fun main() { | ||
val br = BufferedReader(InputStreamReader(System.`in`)) | ||
val n = br.readLine().toInt() | ||
val graph = Array(4) { Array(n + 1) { 0 } } | ||
val dp = Array(4) { Array(n + 1) { 0 } } | ||
for (i in 0 until n) { | ||
val line = br.readLine().split(" ").map { it.toInt() } | ||
for (j in 0..2) { | ||
graph[j + 1][i + 1] = line[j] | ||
} | ||
} | ||
|
||
// ๊ฐ ์ง๋ง๋ค ํ์ฌ ์ด ์์ ์น ํ ๋ ์ต์๊ฐ์ ๊ตฌํ๋ค | ||
for (houseIndex in 1..n) { | ||
for (colorIndex in colors) { | ||
dp[colorIndex][houseIndex] = colors.minOf { | ||
if (it == colorIndex) MAX else dp[it][houseIndex - 1] + graph[colorIndex][houseIndex] | ||
} | ||
} | ||
} | ||
println(colors.minOf { dp[it][n] }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
import kotlin.math.max | ||
import kotlin.math.min | ||
|
||
const val MAX_COST = 10_000 | ||
fun main() { | ||
val br = BufferedReader(InputStreamReader(System.`in`)) | ||
val (n, m) = br.readLine().split(" ").map { it.toInt() } | ||
|
||
// ๋น์ฉ์ ์ต๋๋ 100 * 100 ์ด๋ค | ||
val dp = Array(n + 1) { Array(MAX_COST + 1) { 0 } } | ||
val bytes = listOf(0) + br.readLine().split(" ").map { it.toInt() } | ||
val cost = listOf(0) + br.readLine().split(" ").map { it.toInt() } | ||
|
||
var minCost = Int.MAX_VALUE | ||
for (i in 1..n) { | ||
for (j in 0..MAX_COST) { | ||
// ๋ด์ ์ ์๋ค๋ฉด ์ด์ ์ i-1 ๊น์ง ๋ด์๋์ ๊ฒ ๊ทธ๋๋ก | ||
if (j - cost[i] < 0) { | ||
dp[i][j] = dp[i - 1][j] | ||
continue | ||
} | ||
// ๋ด์ ์ ์๋ค๋ฉด ํ์ฌ ๋น์ฉ - ์ฑ์ ๋น์ฉ ์ต์ ๊ฐ์ ์ป์ ์ ์๋ ์ฉ๋ ๋ํ๊ธฐ | ||
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - cost[i]] + bytes[i]) | ||
|
||
// ๋ชฉํ ์ฉ๋์ ๋์๋ค๋ฉด ์ ๋ต ์ต์๊ฐ ์ ๋ฐ์ดํธ | ||
if (dp[i][j] >= m) { | ||
minCost = min(minCost, j) | ||
} | ||
} | ||
} | ||
println(minCost) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
import java.util.PriorityQueue | ||
|
||
fun main() { | ||
val br = BufferedReader(InputStreamReader(System.`in`)) | ||
val n = br.readLine().toInt() | ||
val numbers = br.readLine().split(" ") | ||
val queue = PriorityQueue<Target>() | ||
numbers.forEach { | ||
queue.add(Target(it)) | ||
} | ||
val stringBuilder = StringBuilder() | ||
while (queue.isNotEmpty()) { | ||
stringBuilder.append(queue.poll().number) | ||
} | ||
if (stringBuilder.all { it == '0' }) { | ||
println(0) | ||
return | ||
} | ||
println(stringBuilder.toString()) | ||
} | ||
|
||
data class Target(val number: String) : Comparable<Target> { | ||
override fun compareTo(other: Target): Int { | ||
return if (number + other.number > other.number + number) -1 else 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from collections import deque | ||
|
||
n, k = map(int, input().split()) | ||
|
||
result = [0] * 100001 | ||
result[n] = 1 | ||
|
||
queue = deque() | ||
queue.append(n) | ||
|
||
while queue: | ||
now = queue.popleft() | ||
if now == k: | ||
break | ||
# -1 ๋ก์ง | ||
if now - 1 >= 0 and result[now-1] == 0 : | ||
queue.append(now-1) | ||
result[now-1] = result[now] + 1 | ||
# +1 ๋ก์ง | ||
if now + 1 < len(result) and result[now+1] == 0: | ||
queue.append(now+1) | ||
result[now+1] = result[now] + 1 | ||
# *2 ๋ก์ง | ||
if now * 2 < len(result) and result[now * 2] == 0: | ||
queue.append(now*2) | ||
result[now*2] = result[now] + 1 | ||
|
||
print(result[k] - 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# n, m = map(int,input()) | ||
|
||
# num = [ i for i in range(n): int(input())] | ||
|
||
# dp = [[-1e9] * m for _ in range(n+1)] | ||
# for i in range(n): | ||
|
||
import sys | ||
input = sys.stdin.readline | ||
|
||
n, m = map(int, input().split()) | ||
dp1 = [[0]+[-1e9]*m for i in range(n+1)] | ||
dp2 = [[0]+[-1e9]*m for i in range(n+1)] | ||
num = [int(input()) for i in range(n) ] | ||
|
||
for i in range(1, n+1): | ||
for j in range(1, min(m, (i+1)//2)+1): | ||
dp2[i][j]=max(dp1[i-1][j], dp2[i-1][j]) | ||
dp1[i][j]=max(dp1[i-1][j], dp2[i-1][j-1])+num[i-1] | ||
print(max(dp1[n][m], dp2[n][m])) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
let n = Int(readLine()!)! | ||
let m = Int(readLine()!)! | ||
|
||
let s = readLine()!.map{$0} | ||
|
||
var result = 0 | ||
var cur = 0 | ||
var count = 0 | ||
|
||
while cur < m-2{ | ||
if String(s[cur...cur + 2]) == "IOI"{ | ||
count += 1 | ||
cur += 2 | ||
if count == n{ | ||
result += 1 | ||
count -= 1 | ||
} | ||
} else { | ||
count = 0 | ||
cur += 1 | ||
} | ||
} | ||
|
||
print(result) | ||
|
||
|
||
""" | ||
50์ ์ง๋ฆฌ ์ฝ๋ | ||
var p = "I" | ||
for _ in 0 ..< n{ | ||
p += "OI" | ||
} | ||
for i in 0..<m-p.count+1{ | ||
if String(s[i..<i+p.count]) == p{ | ||
result += 1 | ||
} | ||
} | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from heapq import * | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
|
||
v, e = map(int, input().split()) | ||
k = int(input()) | ||
|
||
# ๊ทธ๋ํ ๋ง๋ค๊ธฐ | ||
graph = [[] for _ in range(v + 1)] | ||
for _ in range(e): | ||
a, b, c = map(int, input().split()) | ||
graph[a].append((c, b)) | ||
|
||
# ๊ฒฐ๊ณผ ์ ์ฅํ ๋ณ์ ๋ง๋ค๊ธฐ | ||
heap = [] | ||
result = [int(1e9)] * (v + 1) | ||
|
||
# k ๋ฃ๊ธฐ | ||
result[k] = 0 | ||
heappush(heap, (0, k)) | ||
|
||
# ๋ค์ต์คํธ๋ผ ๋๋ฆฌ๊ธฐ | ||
while heap: | ||
weight, now = heappop(heap) | ||
# print(weight,now, heap, result) | ||
if result[now] < weight: | ||
continue | ||
for next_weight, next_node in graph[now]: | ||
total_weight = weight + next_weight | ||
if total_weight < result[next_node]: | ||
result[next_node] = total_weight | ||
heappush(heap, (total_weight, next_node)) | ||
|
||
# ๊ฒฐ๊ณผ ์ถ๋ ฅํ๊ธฐ | ||
for i in range(1, v + 1): | ||
if result[i] == int(1e9): | ||
print("INF") | ||
else: | ||
print(result[i]) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import sys | ||
from heapq import * | ||
|
||
input = sys.stdin.readline | ||
|
||
def dijkstra(graph, start): | ||
distance = [float('inf') for _ in graph] | ||
distance[start] = 0 | ||
queue = [] | ||
heappush(queue, [distance[start], start]) | ||
|
||
while queue: | ||
cur_dist, cur_dest = heappop(queue) | ||
|
||
if distance[cur_dest] < cur_dist: | ||
continue | ||
|
||
for new_dest, new_dist in graph[cur_dest]: | ||
dist = cur_dist + new_dist | ||
if dist < distance[new_dest]: | ||
distance[new_dest] = dist | ||
heappush(queue, [dist, new_dest]) | ||
|
||
return distance | ||
|
||
|
||
items = [] | ||
N, M, R = map(int, input().split()) | ||
|
||
item_weight = list(map(int, input().split())) | ||
graph = [[] for _ in range(N+1)] | ||
|
||
for _ in range(R): | ||
start, end, weight = map(int, input().split()) | ||
graph[start].append((end, weight)) | ||
graph[end].append((start, weight)) | ||
|
||
for item in range(1, len(graph)): | ||
result = dijkstra(graph, item) | ||
can_get = 0 | ||
for i in range(len(result)): | ||
if result[i] <= M: | ||
can_get += item_weight[i-1] | ||
items.append(can_get) | ||
|
||
print(max(items)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
|
||
word = list(input().strip()) | ||
bomb = list(input().strip()) | ||
|
||
key = bomb[-1] | ||
bomb.reverse() | ||
|
||
stack = [] | ||
|
||
for i in range(len(word)): | ||
stack.append(word[i]) | ||
if word[i] == key and len(stack) >= len(bomb): | ||
temp = [] | ||
for j in range(len(bomb)): | ||
temp.append(stack.pop()) | ||
if temp == bomb: | ||
continue | ||
else: | ||
for j in range(len(temp), 0, -1): | ||
stack.append(temp[j-1]) | ||
|
||
if len(stack) == 0: | ||
print('FRULA') | ||
else: | ||
for i in range(len(stack)): | ||
print(stack[i], end='') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
N = int(input()) | ||
dancingCheck = {} | ||
dancingCheck['ChongChong'] = True | ||
for _ in range(N): | ||
left_rabbit, right_rabbit = map(str, input().split()) | ||
try : | ||
if dancingCheck[left_rabbit]: | ||
dancingCheck[right_rabbit] = True | ||
except : | ||
dancingCheck[left_rabbit] = False | ||
|
||
try : | ||
if dancingCheck[right_rabbit] : | ||
dancingCheck[left_rabbit] = True | ||
except : | ||
dancingCheck[right_rabbit] = False | ||
|
||
count=0 | ||
for key in dancingCheck.keys(): | ||
if dancingCheck[key] == True: | ||
count+=1 | ||
|
||
print(count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.