๐Ÿค– 154

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Java] ์บ์‹œ

https://school.programmers.co.kr/learn/courses/30/lessons/17680 ํ”„๋กœ๊ทธ๋ž˜๋จธ์ŠคSW๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ ํ‰๊ฐ€, ๊ต์œก, ์ฑ„์šฉ๊นŒ์ง€ Total Solution์„ ์ œ๊ณตํ•˜๋Š” ๊ฐœ๋ฐœ์ž ์„ฑ์žฅ์„ ์œ„ํ•œ ๋ฒ ์ด์Šค์บ ํ”„programmers.co.kr ์ฒ˜์Œ ์ฝ”๋“œimport java.util.*;class Solution { public int solution(int cacheSize, String[] cities) { if (cacheSize == 0) { return 5 * cities.length; } Deque deque = new ArrayDeque(); Set set = new HashSet()..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Java] ์˜์ƒ

https://school.programmers.co.kr/learn/courses/30/lessons/42578 ํ”„๋กœ๊ทธ๋ž˜๋จธ์ŠคSW๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ ํ‰๊ฐ€, ๊ต์œก, ์ฑ„์šฉ๊นŒ์ง€ Total Solution์„ ์ œ๊ณตํ•˜๋Š” ๊ฐœ๋ฐœ์ž ์„ฑ์žฅ์„ ์œ„ํ•œ ๋ฒ ์ด์Šค์บ ํ”„programmers.co.kr ํ‹€๋ฆฐ ์ฝ”๋“œ import java.util.*;class Solution { private int answer = 0; private Map map1 = new HashMap(); private Map map2 = new HashMap(); private int cnt = 0; private int size; private int[] res; public int solution(S..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Java] ๊ทค ๊ณ ๋ฅด๊ธฐ

https://school.programmers.co.kr/learn/courses/30/lessons/138476 ํ”„๋กœ๊ทธ๋ž˜๋จธ์ŠคSW๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ ํ‰๊ฐ€, ๊ต์œก, ์ฑ„์šฉ๊นŒ์ง€ Total Solution์„ ์ œ๊ณตํ•˜๋Š” ๊ฐœ๋ฐœ์ž ์„ฑ์žฅ์„ ์œ„ํ•œ ๋ฒ ์ด์Šค์บ ํ”„programmers.co.kr ์ฒ˜์Œ ์ฝ”๋“œimport java.util.*;public class Solution { private final int MAX = 10_000_000; private class Tangerine implements Comparable { private int type; private int cnt; public Tangerine(int type, int cnt) { th..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Java] ์ตœ์†Ÿ๊ฐ’ ๋งŒ๋“ค๊ธฐ

https://school.programmers.co.kr/learn/courses/30/lessons/12941 ํ”„๋กœ๊ทธ๋ž˜๋จธ์ŠคSW๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ ํ‰๊ฐ€, ๊ต์œก, ์ฑ„์šฉ๊นŒ์ง€ Total Solution์„ ์ œ๊ณตํ•˜๋Š” ๊ฐœ๋ฐœ์ž ์„ฑ์žฅ์„ ์œ„ํ•œ ๋ฒ ์ด์Šค์บ ํ”„programmers.co.kr ํ‹€๋ฆฐ ์ฝ”๋“œ import java.util.*;import java.util.stream.*;class Solution{ public int solution(int []A, int []B) { List listA = Arrays.stream(A) .boxed() .collect(Collectors.toList())..

๋ฐฑ์ค€ 21921: ๋ธ”๋กœ๊ทธ (Python)

https://www.acmicpc.net/problem/21921 21921๋ฒˆ: ๋ธ”๋กœ๊ทธ ์ฒซ์งธ ์ค„์— $X$์ผ ๋™์•ˆ ๊ฐ€์žฅ ๋งŽ์ด ๋“ค์–ด์˜จ ๋ฐฉ๋ฌธ์ž ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ๋งŒ์•ฝ ์ตœ๋Œ€ ๋ฐฉ๋ฌธ์ž ์ˆ˜๊ฐ€ 0๋ช…์ด๋ผ๋ฉด SAD๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ๋งŒ์•ฝ ์ตœ๋Œ€ ๋ฐฉ๋ฌธ์ž ์ˆ˜๊ฐ€ 0๋ช…์ด ์•„๋‹Œ ๊ฒฝ์šฐ ๋‘˜์งธ ์ค„์— ๊ธฐ๊ฐ„์ด ๋ช‡ ๊ฐœ ์žˆ๋Š”์ง€ ์ถœ๋ ฅํ•œ๋‹ค www.acmicpc.net ํˆฌ ํฌ์ธํ„ฐ ์ด์šฉ n, x = map(int, input().split()) visitors = list(map(int, input().split())) i = j = 0 temp = result = 0 cnt = 0 for i in range(n): # ๋ ํฌ์ธํ„ฐ ์ด๋™ while j-i < x and j < n: temp += visitors[j] j += 1 # x์ผ if j-i == x..

ํˆฌ ํฌ์ธํ„ฐ (Two Pointers)

ํˆฌ ํฌ์ธํ„ฐ ๋ฆฌ์ŠคํŠธ์— ์ˆœ์ฐจ์ ์œผ๋กœ ์ ‘๊ทผํ•ด์•ผ ํ•  ๋•Œ 2๊ฐœ์˜ ์  ์œ„์น˜๋ฅผ ๊ธฐ๋กํ•˜๋ฉด์„œ ์ฒ˜๋ฆฌ ํŠน์ •ํ•œ ํ•ฉ์„ ๊ฐ€์ง€๋Š” ๋ถ€๋ถ„ ์—ฐ์† ์ˆ˜์—ด ์ฐพ๊ธฐ * ๊ธฐ๋ณธ์ ์œผ๋กœ ์‹œ์ž‘์ ์„ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ด๋™์‹œํ‚ค๋ฉด ํ•ญ์ƒ ํ•ฉ์ด ๊ฐ์†Œํ•˜๊ณ , ๋์ ์„ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ด๋™์‹œํ‚ค๋ฉด ํ•ญ์ƒ ํ•ฉ์ด ์ฆ๊ฐ€ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํˆฌ ํฌ์ธํ„ฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค. * ๋ฆฌ์ŠคํŠธ ๋‚ด ์›์†Œ์— ์Œ์ˆ˜ ๋ฐ์ดํ„ฐ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๋Š” ๊ฒฝ์šฐ, ํˆฌ ํฌ์ธํ„ฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์—†๋‹ค. n = 5 # ๋ฐ์ดํ„ฐ์˜ ๊ฐœ์ˆ˜ m = 5 # ์ฐพ๊ณ ์ž ํ•˜๋Š” ๋ถ€๋ถ„ํ•ฉ data = [1, 2, 3, 2, 5] # ์ „์ฒด ์ˆ˜์—ด count = 0 interval_sum = 0 end = 0 # start๋ฅผ ์ฐจ๋ก€๋Œ€๋กœ ์ฆ๊ฐ€์‹œํ‚ค๋ฉฐ ๋ฐ˜๋ณต for start in range(n): # end๋ฅผ ๊ฐ€๋Šฅํ•œ ๋งŒํผ ์ด๋™์‹œํ‚ค๊ธฐ while interval_su..

๋ฐฑ์ค€ 16918: ๋ด„๋ฒ„๋งจ (Python)

https://www.acmicpc.net/problem/16918 16918๋ฒˆ: ๋ด„๋ฒ„๋งจ ์ฒซ์งธ ์ค„์— R, C, N (1 ≤ R, C, N ≤ 200)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ R๊ฐœ์˜ ์ค„์— ๊ฒฉ์žํŒ์˜ ์ดˆ๊ธฐ ์ƒํƒœ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋นˆ ์นธ์€ '.'๋กœ, ํญํƒ„์€ 'O'๋กœ ์ฃผ์–ด์ง„๋‹ค. www.acmicpc.net n=0์ผ ๋•Œ: ํญํƒ„ ์„ค์น˜ n=1์ผ ๋•Œ: ๊ทธ๋Œ€๋กœ n=2์ผ ๋•Œ~: ๋‚˜๋จธ์ง€ ๋ชจ๋“  ์นธ์— ํญํƒ„ ์„ค์น˜ -> ํญ๋ฐœ ๋ฐ˜๋ณต r*c ํฌ๊ธฐ์˜ bombs ๋ฐฐ์—ด์„ ๋ชจ๋‘ 0์œผ๋กœ ์ดˆ๊ธฐํ™”ํ•˜๊ณ , ์ดˆ๊ธฐ ์ƒํƒœ ๋ฐฐ์—ด์„ ์ž…๋ ฅ๋ฐ›์œผ๋ฉด์„œ 'O'์ธ ๋ถ€๋ถ„์€ 2๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค. (0์ดˆ - 1์ดˆ ์ƒํƒœ) i=2๋ถ€ํ„ฐ n+1๊นŒ์ง€ for๋ฌธ์„ ๋Œ๋ ค์ฃผ๋ฉด์„œ 1. bombs ์ˆœํšŒํ•˜๋ฉด์„œ ๊ฐ’์„ ํ•˜๋‚˜์”ฉ ๊ฐ์†Œ์‹œํ‚ค๊ณ , 2. i๊ฐ€ ์ง์ˆ˜์ผ ๋•Œ์—๋Š” ๋ชจ๋“  ์นธ์— ํญํƒ„ ์„ค์น˜ -> 0์ธ ๋ถ€๋ถ„์„ 3์œผ๋กœ ..

๋ฐฑ์ค€ 12933: ์˜ค๋ฆฌ (Python)

https://www.acmicpc.net/problem/12933 12933๋ฒˆ: ์˜ค๋ฆฌ ์ฒซ์งธ ์ค„์— ์˜์„ ์ด๊ฐ€ ๋…น์Œํ•œ ์†Œ๋ฆฌ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์†Œ๋ฆฌ์˜ ๊ธธ์ด๋Š” 5๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 2500๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๊ณ , 'q','u','a','c','k'๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. www.acmicpc.net ๋กœ์ง์€ ์ด๋Ÿฌํ•จ.. ์ด๋•Œ๊นŒ์ง€๋งŒ ํ•ด๋„ ์‰ฌ์šด ๋ฌธ์ œ์ธ ์ค„ ์•Œ์•˜์ง€.. ์ฒซ ์‹œ๋„ (์‹คํŒจ) sound๋ฅผ ์ฐจ๋ก€๋Œ€๋กœ ์ˆœํšŒํ•˜๋ฉด์„œ q -> u -> a -> c -> k ์— ํ•ด๋‹นํ•˜๋ฉด ๋„˜์–ด๊ฐ€๊ณ , ํ•ด๋‹นํ•˜์ง€ ์•Š์œผ๋ฉด temp ๋ฐฐ์—ด์— ๋ฌธ์ž๋ฅผ ๋„ฃ๋Š”๋‹ค. ์ˆœํšŒ๊ฐ€ ๋๋‚œ ํ›„ sound์™€ temp๊ฐ€ ๊ฐ™๋‹ค๋ฉด (q-u-a-c-k๋ฅผ ์ฐพ์ง€ ๋ชปํ•œ ๊ฒฝ์šฐ) breakํ•ด์ฃผ๊ณ , ๊ฐ™์ง€ ์•Š๋‹ค๋ฉด sound = temp ํ›„ ์ •๋‹ต์„ ํ•˜๋‚˜์”ฉ ์ถ”๊ฐ€ํ–ˆ๋‹ค. sound = input() du..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค | Lv3] ํผ์ฆ ์กฐ๊ฐ ์ฑ„์šฐ๊ธฐ (Python)

https://school.programmers.co.kr/learn/courses/30/lessons/84021 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ „์ฒด ๋กœ์ง 1. table -> ์ด์–ด์ง„ ํผ์ฆ ์กฐ๊ฐ ๋ถ€๋ถ„๋งŒ ์ž˜๋ผ์„œ ํ–‰๋ ฌ๋กœ ๋งŒ๋“ค์–ด์ฃผ๊ณ  board์— ์ถ”๊ฐ€ 2. game_board -> ์ด์–ด์ง„ ๋นˆ ๋ถ€๋ถ„๋งŒ ์ž˜๋ผ์„œ ํ–‰๋ ฌ๋กœ ๋งŒ๋“ค์–ด์ฃผ๊ณ  rotateํ•˜๋ฉด์„œ ๊ฐ ์ˆ˜ํ–‰๋ฌธ๋งˆ๋‹ค board์— ๊ฐ™์€ ๊ฐ’์ด ์žˆ๋Š”์ง€ ์ฐพ๊ณ  ์ •๋‹ต ์ถ”๊ฐ€ bfs(x, y, t, f, array, size) - ํ์— [x, y]๋ฅผ ๋„ฃ๊ณ  ์ด์–ด์ง„ ๋ถ€๋ถ„์„ ์ฐพ๋Š”๋‹ค. - table์€ 1์„ ์ฐพ์•„์•ผ ํ•˜๊ณ , game..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค | Lv2] ์กฐ์ด์Šคํ‹ฑ (Python)

https://school.programmers.co.kr/learn/courses/30/lessons/42860 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr 1. ์ƒํ•˜์ด๋™ ๋”ํ•˜๊ธฐ (A-Z) - ์•„์Šคํ‚ค์ฝ”๋“œ๋ฅผ ์ด์šฉํ•ด ์•ž์—์„œ๋ถ€ํ„ฐ ๋”ํ•œ ๊ฒƒ๊ณผ ๋’ค์—์„œ๋ถ€ํ„ฐ ๋”ํ•œ ๊ฒƒ ์ค‘ ์ตœ์†Ÿ๊ฐ’์„ ์ฐพ์•„์ค€๋‹ค. 2. ์ขŒ์šฐ์ด๋™์˜ ์ตœ์†Œ ๊ตฌํ•˜๊ธฐ 1) 'A'๊ฐ€ ์—ฐ์†ํ•ด์„œ ๋‚˜์˜ค๋Š” ์œ„์น˜๋ฅผ ์ฐพ์•„์ค€๋‹ค. - temp ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค์–ด์„œ ์—ฐ์†๋œ ์ธ๋ฑ์Šค๋“ค์„ ๋ฆฌ์ŠคํŠธ๋กœ ๋ฌถ์–ด์„œ ๋„ฃ์–ด์คฌ๋‹ค. 2) ๊ธฐ์กด ๋ฐฉ์‹(์•ž์œผ๋กœ ์ญ‰ ๊ฐ€๊ธฐ) / ์•ž์œผ๋กœ ๊ฐ”๋‹ค๊ฐ€ ๋’ค๋กœ ๋Œ์•„๊ฐ€๊ธฐ / ๋’ค๋กœ ๊ฐ”๋‹ค๊ฐ€ ์•ž์œผ๋กœ ๋Œ์•„๊ฐ€๊ธฐ ์ค‘ ์ตœ์†Ÿ๊ฐ’ - ๊ธฐ์กด ๋ฐฉ์‹(์•ž์œผ..