Algorithm

Algorithm/BOJ

[BOJ] 1920๋ฒˆ ์ˆ˜์ฐพ๊ธฐ / ์ด๋ถ„ํƒ์ƒ‰ / ํ•ด์‹œํ…Œ์ด๋ธ”

https://www.acmicpc.net/problem/1920 1920๋ฒˆ: ์ˆ˜ ์ฐพ๊ธฐ ์ฒซ์งธ ์ค„์— ์ž์—ฐ์ˆ˜ N(1 ≤ N ≤ 100,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ ์ค„์—๋Š” N๊ฐœ์˜ ์ •์ˆ˜ A[1], A[2], …, A[N]์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ ์ค„์—๋Š” M(1 ≤ M ≤ 100,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ ์ค„์—๋Š” M๊ฐœ์˜ ์ˆ˜๋“ค์ด ์ฃผ์–ด์ง€๋Š”๋ฐ, ์ด ์ˆ˜๋“ค www.acmicpc.net ์ˆ˜ ์ฐพ๊ธฐ ์„ฑ๊ณต ์‹œ๊ฐ„ ์ œํ•œ๋ฉ”๋ชจ๋ฆฌ ์ œํ•œ์ œ์ถœ์ •๋‹ต๋งžํžŒ ์‚ฌ๋žŒ์ •๋‹ต ๋น„์œจ 1 ์ดˆ 128 MB 217313 66856 44340 30.018% ๋ฌธ์ œ N๊ฐœ์˜ ์ •์ˆ˜ A[1], A[2], …, A[N]์ด ์ฃผ์–ด์ ธ ์žˆ์„ ๋•Œ, ์ด ์•ˆ์— X๋ผ๋Š” ์ •์ˆ˜๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ์•Œ์•„๋‚ด๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…๋ ฅ ์ฒซ์งธ ์ค„์— ์ž์—ฐ์ˆ˜ N(1 ≤ N ≤ 100,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ ์ค„์—๋Š” ..

Algorithm/BOJ

[BOJ] ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ ์œ ํ˜• ๋ชจ์Œ

1-1. ํƒ์ƒ‰๊ณผ ์ •๋ ฌ (1) A – 1920 ์ˆ˜ ์ฐพ๊ธฐ https://www.acmicpc.net/problem/1920 B – 2750 ์ˆ˜ ์ •๋ ฌํ•˜๊ธฐ https://www.acmicpc.net/problem/2750 C – 2751 ์ˆ˜ ์ •๋ ฌํ•˜๊ธฐ 2 https://www.acmicpc.net/problem/2751 D – 10989 ์ˆ˜ ์ •๋ ฌํ•˜๊ธฐ 3 https://www.acmicpc.net/problem/10989 E – 10815 ์ˆซ์ž ์นด๋“œ https://www.acmicpc.net/problem/10815 1-2. ๊ธฐ์ดˆ ์ž๋ฃŒ๊ตฌ์กฐ (1) A – 10828 ์Šคํƒ https://www.acmicpc.net/problem/10828 B – 10845 ํ https://www.acmicpc.net/problem/..

Algorithm/Softeer

[Softeer - level2] ๋ฐ”์ด๋Ÿฌ์Šค

# ๋ฐ”์ด๋Ÿฌ์Šค 1์ดˆ๋‹น P๋ฐฐ์”ฉ ์ฆ๊ฐ€ # ์ฒ˜์Œ K๋งˆ๋ฆฌ n์ดˆํ›„ -> ๋ช‡๋งˆ๋ฆฌ? # k:๋ฐ”์ด๋Ÿฌ์Šค ์ˆ˜ , P:์ฆ๊ฐ€์œจ , N:์ด ์‹œ๊ฐ„ k,p,n = map(int,input().split()) result = k for _ in range(n): a = result % 1000000007 b = p % 1000000007 result = (a*b) % 1000000007 print(result) (a*b) % m = ( (a%m) * (b%m) ) % m https://sskl660.tistory.com/75 ๋ชจ๋“ˆ๋Ÿฌ ์‚ฐ์ˆ (Modular Arithmetic) *๋ชจ๋“ˆ๋Ÿฌ ์‚ฐ์ˆ (Modular Arithmetic) -> ๋ชจ๋“ˆ๋Ÿฌ ์‚ฐ์ˆ (๋ชจ๋“ˆ๋Ÿฌ ์—ฐ์‚ฐ)์€ ์ •์ˆ˜์˜ ํ•ฉ๊ณผ ๊ณฑ์„ ์–ด๋–ค ์ฃผ์–ด์ง„ ์ˆ˜์˜ ๋‚˜๋จธ์ง€๋ฅผ ์ด์šฉํ•˜์—ฌ ์ •์˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋งํ•œ๋‹ค. ..

Algorithm/Softeer

[Softeer - level2] ๊ธˆ๊ณ ํ„ธ์ด

import sys input = sys.stdin.readline # ๋ฐฐ๋‚ญ ๋ฌด๊ฒŒ ์ œํ•œ W , n์ข…๋ฅ˜์˜ ๊ท€๊ธˆ์† # ๊ฐ€์žฅ ๋†’์€ ๊ฐ€๊ฒฉ์œผ๋กœ ๋ฐฐ๋‚ญ ์ฑ„์šฐ๊ธฐ w,n = map(int,input().split()) total_price = 0 #๋ฆฌ์ŠคํŠธ ์ปดํ”„๋ฆฌํ—จ์…˜ arr = [list(map(int,input().split())) for _ in range(n)] arr.sort(key = lambda x:x[1],reverse=True) idx = 0 while w>0: if arr[idx][0] >= w: total_price += arr[idx][1]*w break else: total_price += arr[idx][0]*arr[idx][1] w -= arr[idx][0] idx += 1 print(total_..

Algorithm/Softeer

[Softeer - level2] ์ง€๋„ ์ž๋™ ๊ตฌ์ถ•

import sys n = int(input()) line_dot = 2 for _ in range(n): line_dot += line_dot-1 print(line_dot**2) ์ ํ™”์‹์„ ๊ตฌํ•˜์—ฌ ํ’€์ด

Algorithm/Softeer

[Softeer - level2] 8๋‹จ ๋ณ€์†๊ธฐ

import sys arr = list(map(int,input().split())) asc = list(range(1,9)) desc = list(range(8,0,-1)) result = "" if arr==asc: result = "ascending" elif arr==desc: result = "descending" else: result = "mixed" print(result)

Algorithm/Softeer

[Softeer - level3] ์Šค๋งˆํŠธ ๋ฌผ๋ฅ˜

import sys input = sys.stdin.readline n,k = map(int,input().split()) line = list(input()) check = [0]*n # P:๋กœ๋ด‡ , H:๋ถ€ํ’ˆ for i in range(n): if line[i] == "P": for j in range(i-k,i+k+1): if (i==j) or (j=n): continue if line[j] == "H" and check[j] == 0 : check[j] = 1 break print(sum(check)) N์€ 20000๋ณด๋‹ค ์ž‘๊ณ , K๋Š” 10๋ณด๋‹ค ์ž‘๊ธฐ ๋–„๋ฌธ์— ์™„์ „ํƒ์ƒ‰ ๊ฐ€๋Šฅ ์ธ๋ฑ์Šค i ๊ธฐ์ค€์œผ๋กœ ์–‘์˜†์œผ๋กœ ์ฒดํฌ i == j (๋กœ๋ด‡ ์ž๊ธฐ ์ž์‹ ์˜ ์œ„์น˜ X) j๊ฐ€ ์˜์—ญ ๋ฐ– (์–‘์˜†์œผ๋กœ ์ฒดํฌ) continue์ฒ˜๋ฆฌ c..

Algorithm/Softeer

[Softeer - level3] ํƒ๋ฐฐ ๋งˆ์Šคํ„ฐ ๊ด‘์šฐ

import sys input = sys.stdin.readline from itertools import permutations # ๋ ˆ์ผ์˜ ์ˆœ์„œ๋ฅผ ์กฐ์ž‘ํ•ด์„œ ์ตœ์†Œํ•œ์˜ ๋ฌด๊ฒŒ๋งŒ ๋“ค ์ˆ˜ ์žˆ๊ฒŒ ํ•˜์ž n,m,k = map(int,input().split()) # n : ๋ ˆ์ผ / m : ํƒ๋ฐฐ ๋ฌด๊ฒŒ / k : ์‹œํ–‰ ํšŸ์ˆ˜ result = 100000 # ์ตœ์†Œ๋ฌด๊ฒŒ rail = list(map(int,input().split())) rail_list = list(permutations(rail)) # ์ˆœ์—ด def cal(current): total_weight, weight = 0, current[0] idx, cnt = 0, 0 while cnt < k: next_weight = current[(idx+1)%n] if ..

hello_u
'Algorithm' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก