๐Ÿค– ์•Œ๊ณ ๋ฆฌ์ฆ˜ 43

baekjoon. ํฌ๊ฒŒ ๋งŒ๋“ค๊ธฐ (2812) [python][Gold III]

๋ฌธ์ œ ๋งํฌ : https://www.acmicpc.net/problem/2812 >> ์ ‘๊ทผ๋ฐฉ๋ฒ• - ์ˆซ์ž k๊ฐœ๋ฅผ ์ง€์› ์„๋•Œ ๋งจ ์•ž์˜ ์ˆ˜๊ฐ€ ๊ฐ€์žฅ ํด์ˆ˜๋กœ ์ •๋‹ต์ธ ๊ฐ€์žฅ ํฐ ์ˆ˜๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค. ๋‚ด๊ฐ€ ์ฒ˜์Œ์— ํ’€์—ˆ๋˜ ์ ‘๊ทผ์€ ์ˆซ์ž ์ค‘์—์„œ ์ œ์ผ ํฐ ์ˆซ์ž๋“ค์„ ๋‚จ๊ธฐ๋Š” ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผํ–ˆ๋Š”๋ฐ, ๊ทธ๋Ÿด๊ฒฝ์šฐ ์„ธ๋ฒˆ์งธ ์˜ˆ์‹œ์—์„œ 477584๊ฐ€ ๋‚จ์œผ๋ฉด์„œ 775841์—์„œ ๋‹ต์ด ํ‹€๋ฆฐ๋‹ค. - ์ด๋ฅผ ์œ„ํ•ด ํ˜„์žฌ ์ธ๋ฑ์Šค ์œ„์น˜๊ฐ’๋ณด๋‹ค ์™ผ์ชฝ(-1 ์œ„์น˜)๊ฐ’์ด ์ž‘๊ณ  ์ง€์šธ ์ˆ˜ ์žˆ๋Š” ํšŸ์ˆ˜ k๊ฐ€ ๋‚จ์•„์žˆ๋‹ค๋ฉด ํ˜„์žฌ ์ธ๋ฑ์Šค ์™ผ์ชฝ (-1) ๊ฐ’์„ ์ง€์›Œ์ฃผ๋ฉด ๋œ๋‹ค. >> ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด N, K = map(int, input().split()) num = input() stack = [] cnt = K for i in num: # ํ˜„์žฌ i๊ฐ€ stack์— ์žˆ๋Š” ๊ฐ’๋ณด๋‹ค ํฌ๋‹ค๋ฉด ์ œ๊ฑฐ ..

baekjoon. ํ2 (18258) [python][Silver IV]

๋ฌธ์ œ : https://www.acmicpc.net/problem/18258 18258๋ฒˆ: ํ 2 ์ฒซ์งธ ์ค„์— ์ฃผ์–ด์ง€๋Š” ๋ช…๋ น์˜ ์ˆ˜ N (1 ≤ N ≤ 2,000,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ๋ช…๋ น์ด ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ์ •์ˆ˜๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 100,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ๋ฌธ์ œ์— ๋‚˜์™€์žˆ์ง€ www.acmicpc.net ๋ฌธ์ œํ’€์ด import sys from collections import deque n = int(input()) queue = deque([]) for i in range(n): str = sys.stdin.readline() strArray = str.split() command = strArray[0] if len(strArray) > 1: args = str..

baekjoon. ์‡ ๋ง‰๋Œ€๊ธฐ (10799) [python][Silver II]

๋ฌธ์ œ ๋งํฌ : https://www.acmicpc.net/problem/10799 ๋ฌธ์ œ ํ’€์ด sticks = input() stack = [] count = 0 for i in range(len(sticks)): cur = sticks[i] # ( ๋งŒ๋‚˜๋ฉด stack push if (cur == '('): stack.append(cur) # ์ตœ์ƒ๋‹จ์ด (์ด๊ณ  ๊ทธ ๋‹ค์Œ์ด) ์ด๋ฉด size ์ถ”๊ฐ€ # ) ๋งŒ๋‚˜๋ฉด 1 ์ถ”๊ฐ€ elif (cur == ')'): stack.pop() if (sticks[i - 1] == '('): count += len(stack) else: count = count + 1 # print(i, ' : ', cur, ' - ', count) print(count) ((( () () ))) ๋ฅผ..

baekjoon. ์Šคํƒ (10828) [python][Silver IV]

๋ฌธ์ œ ๋งํฌ : https://www.acmicpc.net/problem/10828 ๋ฌธ์ œํ’€์ด import sys stack = [] # stack = array : ๋ณต์žกํ•˜๊ฒŒ ํด๋ž˜์Šค๋กœ ๋งŒ๋“ค ํ•„์š” ์—†๋‹ค def push(data): stack.append(data) def pop(): if (empty()): print(-1) else: lastIndex = len(stack) -1 print(stack.pop(lastIndex)) # remove (value), pop (index) def size(): print(len(stack)) def empty(): if len(stack) == 0: return 1 else: return 0 def top(): if (empty()): print(-1) else: ..

baekjoon. ํšŒ์ „ ์ดˆ๋ฐฅ (2531) | hashmap์‚ฌ์šฉ [java]

์—ฌ๊ธฐ ๋ฌธ์ œ์ง‘์—์„œ ํšŒ์ „์ดˆ๋ฐฅ ๋ฌธ์ œ๋ฅผ ํ’€์—ˆ๋‹ค. ใ„ด ๋ฌธ์ œ์ง‘ : https://www.acmicpc.net/workbook/view/8708 ใ„ด ๋ฌธ์ œ : https://www.acmicpc.net/problem/2531 ๋ฌธ์ œ๊ฐ€ ์กฐ๊ธˆ ๊ธธ๊ฒŒ ์„ค๋ช…์ด ๋˜์–ด์žˆ๋Š”๋ฐ ์š”์•ฝํ•˜๋ฉด - ์—ฐ์†์œผ๋กœ ๋จน์„ ์ˆ˜ ์žˆ๋Š” ์ดˆ๋ฐฅ์— ์ตœ๋Œ€ํ•œ ์ˆซ์ž๊ฐ€ ๊ณ ์œ ํ•˜๊ฒŒ ๋“ค์–ด๊ฐ€๋ฉด ๋œ๋‹ค. - ๊ทธ๋ฆฌ๊ณ  ๋‚˜์„œ ์ด ์ดˆ๋ฐฅ์— ์ฟ ํฐ์ดˆ๋ฐฅ์ด ๋“ค์–ด๊ฐ€์žˆ์œผ๋ฉด ๊ทธ๋Œ€๋กœ ๋‘๊ณ , ์•„๋‹ˆ๋ผ๋ฉด ์ฟ ํฐ์ดˆ๋ฐฅ์„ +1ํ•˜๋ฉด ๋œ๋‹ค. ์ดˆ๋ฐฅ ๊ทธ๋ฆ‡ ๊ฐฏ์ˆ˜ (n)์— ๋งค๋ฒˆ for๋ฌธ์„ ๋Œ๋ฉด์„œ ์—ฐ์† ์ˆซ์ž (k)๋ฅผ ์ฒดํฌํ•˜๋ฉด ๋˜๋Š”๋ฐ ๊ทธ๋Ÿด ๊ฒฝ์šฐ n์ตœ๋Œ€ 30,000์— k 3,000๊นŒ์ง€ ํ•ด์„œ ์‹œ๊ฐ„์ด ์˜ค๋ž˜ ๊ฑธ๋ฆด ๊ฒƒ ๊ฐ™์•„์„œ ํšจ์œจ์ ์ธ ๋ฐฉ๋ฒ•์„ ์ฐพ์•„์•ผ ๋˜์—ˆ์—ˆ๋‹ค. ๊ทธ๋ž˜์„œ ์ดˆ๋ฐฅ ๊ทธ๋ฆ‡ ๊ฐฏ์ˆ˜ (n)์—์„œ ๊ฐ ์ดˆ๋ฐฅ๋งˆ๋‹ค HashMap์œผ๋กœ ๋ช‡๋ฒˆ์˜ ์ดˆ๋ฐฅ์ด ๋ช‡..

baekjoon. ํŒŒํ‹ฐ

๋ฌธ์ œ์ง‘ : https://www.acmicpc.net/workbook/view/8708 ํ’€์ด : https://www.acmicpc.net/problem/1238 ๋ฌธ์ œ์— ์ •๋ง ๋„์›€๋˜์—ˆ๋˜ ๋ธ”๋กœ๊ทธ https://loosie.tistory.com/209 1. ํ”Œ๋กœ์ด๋“œ ์™€์ƒฌ๋กœ ํ’€์ด ๊ฒฝ๋กœ๋ณ„๋กœ ์ตœ๋‹จ ๊ฑฐ๋ฆฌ๋ฅผ ์ €์žฅํ•ด์„œ ์ตœ์ข…์ ์œผ๋กœ ๋น„๊ตํ•˜๋Š” ํ’€์ด์ด๋‹ค. ์—ฌ๊ธฐ์„œ ์ค‘์š”ํ–ˆ๋˜ ๊ฑด์€ ์ดˆ๊ธฐ์— ์„ธํŒ…ํ• ๋•Œ ๊ฐ’์„ ์ง€์ •ํ•˜๋Š” ๊ฒƒ์ด์—ˆ๋Š”๋ฐ, Integer.MAX_VALUE๋กœ ์„ธํŒ…ํ•˜๋ฉด ๊ฐ’์„ ๋น„๊ตํ•˜๋Š” ๊ณผ์ •์—์„œ ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ๊ฐ€ ๋ฐœ์ƒํ•˜๊ณ  ๋ฌธ์ œ์— ๋”ฐ๋ผ ๊ฑฐ๋ฆฌ ์ตœ๋Œ€๊ฐ’์ธ 100์œผ๋กœ ์„ธํŒ…ํ•˜๋ฉด ๊ฒฝ๋กœ๋ฅผ ํ•ฉ์น˜๋ฉด์„œ 100์„ ์ดˆ๊ณผํ•˜์—ฌ ์˜๋„ํ–ˆ๋˜ ๊ฒฐ๊ณผ๊ฐ€ ๋Œ์•„๊ฐ€์ง€ ์•Š์•˜๋‹ค๋Š” ์‚ฌ์‹ค์ด์—ˆ๋‹ค. ๊ฒฐ๊ตญ ์ ๋‹นํ•œ ๊ฐ’์œผ๋กœ ์„ธํŒ…ํ•ด์„œ ๋ฌธ์ œ๋ฅผ ํ’€์—ˆ๋‹ค. import java.io.BufferedReader..

baekjoon. ๋Œ ๊ฒŒ์ž„

์—ฌ๊ธฐ ๋ฌธ์ œ์ง‘์—์„œ ๋Œ ๊ฒŒ์ž„ ๋ฌธ์ œ๋ฅผ ํ’€์—ˆ๋‹ค. ใ„ด ๋ฌธ์ œ์ง‘ : https://www.acmicpc.net/workbook/view/8708 ใ„ด ๋ฌธ์ œ : https://www.acmicpc.net/problem/9655 DP๋กœ ์ ‘๊ทผํ•ด์•ผ ํ•˜๋‚˜ ์ƒ๊ฐํ•˜๋ฉด์„œ ํ•˜๋‚˜์”ฉ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค๋ฅผ ์ž‘์„ฑํ–ˆ๋Š”๋ฐ, ํ™€์ˆ˜๋ƒ ์ง์ˆ˜๋ƒ ์ธ์ง€๋งŒ ํŒ๋‹จํ•ด์ฃผ๋ฉด ๋ฌธ์ œ ํ•ด๊ฒฐ. 1๊ฐœ : ์ƒ๊ทผ 2๊ฐœ : ์ƒ๊ทผ ์ฐฝ์˜ 3๊ฐœ : - ์ƒ๊ทผ (3) - ์ƒ๊ทผ ์ฐฝ์˜ ์ƒ๊ทผ 4๊ฐœ : - ์ƒ๊ทผ(3) ์ฐฝ์˜ - ์ƒ๊ทผ(1) ์ฐฝ์˜(3) - ์ƒ๊ทผ ์ฐฝ์˜ ์ƒ๊ทผ ์ฐฝ์˜ 5๊ฐœ : - ์ƒ๊ทผ(3) ์ฐฝ์˜(1) ์ƒ๊ทผ(1) - ์ƒ๊ทผ(1) ์ฐฝ์˜(3) ์ƒ๊ทผ(1) - ์ƒ๊ทผ(1) ์ฐฝ์˜(1) ์ƒ๊ทผ(3) 6๊ฐœ : - ์ƒ๊ทผ(3) ์ฐฝ์˜(3) - ์ƒ๊ทผ(3) ์ฐฝ์˜(1) ์ƒ๊ทผ(1) ์ฐฝ์˜(1) - ์ƒ๊ทผ(1) ์ฐฝ์˜(3) ์ƒ๊ทผ(1) ..

baekjoon. ๋ฌธ์ž์—ด ํญ๋ฐœ

9935๋ฒˆ: ๋ฌธ์ž์—ด ํญ๋ฐœ ์ฒซ์งธ ์ค„์— ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 1,000,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ๋‘˜์งธ ์ค„์— ํญ๋ฐœ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ๊ธธ์ด๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 36๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ๋‘ ๋ฌธ์ž์—ด์€ ๋ชจ www.acmicpc.net ๋‚ด ํ’€์ด import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Scanner; import java.util.Stack; import java.util.HashMap; import java.util.ArrayList; public class Main { // ๋ฌธ์ž ๋ณ„๋กœ ์œ„์น˜ ์ €์žฅ static Ha..

programmers. ๋‹ค๋‹จ๊ณ„ ์นซ์†” ํŒ๋งค

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋‹ค๋‹จ๊ณ„ ์นซ์†” ํŒ๋งค ๋ฏผํ˜ธ๋Š” ๋‹ค๋‹จ๊ณ„ ์กฐ์ง์„ ์ด์šฉํ•˜์—ฌ ์นซ์†”์„ ํŒ๋งคํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํŒ๋งค์›์ด ์นซ์†”์„ ํŒ๋งคํ•˜๋ฉด ๊ทธ ์ด์ต์ด ํ”ผ๋ผ๋ฏธ๋“œ ์กฐ์ง์„ ํƒ€๊ณ  ์กฐ๊ธˆ์”ฉ ๋ถ„๋ฐฐ๋˜๋Š” ํ˜•ํƒœ์˜ ํŒ๋งค๋ง์ž…๋‹ˆ๋‹ค. ์–ด๋Š์ •๋„ ํŒ๋งค๊ฐ€ ์ด๋ฃจ์–ด์ง„ ํ›„, programmers.co.kr ๋‚ด๊ฐ€ ์ƒ๊ฐํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋‚ด ํ’€์ด (0.5H) import java.util.HashMap; class Solution { static HashMap relationMaps = new HashMap(); static HashMap payMaps = new HashMap(); public int[] solution(String[] enrolls, String[] referrals, String[] sellers, int[] amounts) { int[] answ..

์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ฟ€ํŒ. ์ž๋ฐ”

1. ๋””๋ฒ„๊น… ์‹œ ๋ฌธ๊ตฌ์™€ ๋ณ€์ˆ˜ ๊ฐ™์ด ์ถœ๋ ฅํ•˜๊ณ  ์‹ถ์„๋•Œ System.out.printf("๋น„๊ต๋ฌธ ์ถœ๋ ฅ %d < %d || %d < %d",a,b,c,d); System.out.printf("๋ฌธ์ž์—ด ์ถœ๋ ฅ %s",e); 2. ์ตœ์†Œ๊ฐ’, ์ตœ๋Œ€๊ฐ’ ๊ตฌํ• ๋•Œ int min = Integer.MAX_VALUE; while (true) { ... min = Math.min(min, origin[currentX][currentY]); ... } return min; 3. ๋ฐฐ์—ด ์ถœ๋ ฅํ•  ๋•Œ import java.util.Arrays; // 1์ฐจ์› ๋ฐฐ์—ด System.out.println(Arrays.toString(arr)); // 2์ฐจ์› ๋ฐฐ์—ด System.out.println(Arrays.deepToString(arr)); 4. h..

๋ฐ˜์‘ํ˜•