-
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 23-alstjr7437
- Loading branch information
Showing
12 changed files
with
266 additions
and
29 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
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,19 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
N = int(input()) | ||
emoji_using_users = set() | ||
time_for_emoji_use = False | ||
emoji_use_count = 0 | ||
for _ in range(N): | ||
chat_string = input().rstrip() | ||
if chat_string == 'ENTER' : | ||
if time_for_emoji_use : | ||
emoji_use_count += len(emoji_using_users) | ||
else : | ||
time_for_emoji_use = True | ||
emoji_using_users = set() | ||
else : | ||
emoji_using_users.add(chat_string) | ||
|
||
emoji_use_count+=len(emoji_using_users) | ||
print(emoji_use_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
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
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 | ||
|
||
def fib(n) : | ||
global countFib | ||
if n==1 or n==2: | ||
countFib += 1 | ||
return 1 | ||
else : | ||
return fib(n-1) + fib(n-2) | ||
|
||
def fibo(n): | ||
global countFibo | ||
f = [0 for _ in range(n+1)] | ||
f[1] = f[2] = 1 | ||
for idx in range(3, n+1): | ||
countFibo+=1 | ||
f[idx] = f[idx-1] + f[idx-2] | ||
return f[n] | ||
|
||
N = int(input()) | ||
countFib = countFibo = 0 | ||
fib(N) | ||
fibo(N) | ||
print(countFib, countFibo) |
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 | ||
|
||
def w(a,b,c): | ||
if a<=0 or b<=0 or c<=0 : | ||
return 1 | ||
if a>20 or b>20 or c>20: | ||
return w(20,20,20) | ||
if dp[a][b][c] : | ||
return dp[a][b][c] | ||
if a<b<c: | ||
dp[a][b][c] = w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c) | ||
return dp[a][b][c] | ||
dp[a][b][c] = w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1) | ||
return dp[a][b][c] | ||
|
||
|
||
dp = [[[0] * 21 for _ in range(21)] for _ in range(21)] | ||
|
||
while True: | ||
a,b,c = map(int, input().split()) | ||
if a==b==c==-1 : break | ||
print(f'w({a}, {b}, {c}) = {w(a,b,c)}') | ||
|
||
|
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 collections import deque | ||
input = sys.stdin.readline | ||
N,L,R = map(int, input().split()) | ||
country = [list(map(int, input().split())) for _ in range(N)] | ||
q = deque() | ||
#์ฐํฉ์ด ๋ ์ ์์์ง ํ์ธ ํ ์ฐ๋์ด ๋๋ฉด ์ ์ฅ | ||
dx = [1,0,-1,0] | ||
dy = [0,1,0,-1] | ||
|
||
def bfs(x,y): | ||
q.append((x,y)) | ||
union=[] | ||
union.append((x,y)) | ||
while q: | ||
a,b = q.popleft() | ||
for i in range(4): | ||
na = a + dx[i] | ||
nb = b + dy[i] | ||
if na >= N or nb>= N or nb<0 or na <0 or visited[na][nb]==1: | ||
continue | ||
if R>=abs(country[a][b]-country[na][nb]) >= L: | ||
visited[na][nb] = 1 | ||
q.append((na,nb)) | ||
union.append((na,nb)) | ||
if len(union)<=1: | ||
return 0 | ||
result=sum(country[a][b] for a,b in union) // len(union) | ||
for a,b in union: | ||
country[a][b] = result | ||
|
||
return 1 | ||
day=0 | ||
|
||
while True : | ||
stop = 0 | ||
visited = [[0]*N for _ in range(N)] | ||
for i in range(N): | ||
for j in range(N): | ||
if visited[i][j] == 0: | ||
visited[i][j] = 1 | ||
stop += bfs(i,j) | ||
if stop ==0: | ||
break | ||
day+=1 | ||
print(day) |