Algorithm/Softeer

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 ..

Algorithm/Softeer

[Softeer - level2] [21๋…„ ์žฌ์ง์ž ๋Œ€ํšŒ ์˜ˆ์„ ] ๋น„๋ฐ€ ๋ฉ”๋‰ด

import sys input = sys.stdin.readline # ์žํŒ๊ธฐ์— ์ด k๊ฐœ์˜ ๋ฒ„ํŠผ ์กด์žฌ (1~k) # ๋น„๋ฐ€๋ฒˆํ˜ธ = m๊ฐœ์˜ ๋ฒ„ํŠผ ์ˆœ์„œ๋Œ€๋กœ ๋ˆ„๋ฅด๊ธฐ # ์‚ฌ์šฉ์ž๊ฐ€ n๊ฐœ์˜ ๋ฒ„ํŠผ ๋ˆ„๋ฆ„ m, n, k = map(int,input().split()) password_list = input().split() client_list = input().split() password = "" client = "" for x in password_list: password += x for x in client_list: client += x if password in client: print("secret") else: print("normal") join ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„ ์ฝ”๋“œ๊ฐ€ ๊ธธ์–ด์ง ๋ฌธ์ž์—ด ํ•ฉ์น˜๊ธฐ - jo..

Algorithm/Softeer

[Softeer - level2] GBC

๋ฐฐ์—ด 1์นธ์„ 1m๋กœ ์ƒ๊ฐํ•˜๊ณ  ๊ฐ ๋ฐฐ์—ด๋งˆ๋‹ค ์ œํ•œ ์†๋„๋ฅผ ์ง€์ •ํ•˜์˜€๋‹ค. import sys input = sys.stdin.readline # ์ œํ•œ ์†๋„๋ฅผ ๊ฐ€์žฅ ํฌ๊ฒŒ ๋ฒ—์–ด๋‚œ ๊ฐ’์„ ์ถœ๋ ฅ # ์ œํ•œ ์†๋„๋ฅผ ๋ฒ—์–ด๋‚˜์ง€ ์•Š์€ ๊ฒฝ์šฐ๋Š” 0์„ ์ถœ๋ ฅ sec_list = [] test_list = [] sec_n,test_m = map(int,input().split()) for _ in range(sec_n): a,b = map(int,input().split()) for _ in range(a): sec_list.append(b) for _ in range(test_m): a,b = map(int,input().split()) for _ in range(a): test_list.append(b) result = 0 # ์ œํ•œ ..

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