-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
299 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import sys | ||
from collections import deque | ||
|
||
def input() : return sys.stdin.readline().rstrip() | ||
|
||
t = int(input()) | ||
dx = [-1, 1, 0, 0] | ||
dy = [0, 0, -1, 1] | ||
|
||
|
||
for i in range(t): | ||
n = int(input()) | ||
hx, hy = map(int, input().split()) | ||
store = [list(map(int, input().split())) for _ in range(n)] | ||
fx, fy = map(int, input().split()) | ||
|
||
x, y = hx, hy | ||
result = "sad" | ||
|
||
q = deque([(x, y, 20)]) | ||
visited = set([x, y]) | ||
|
||
while q: | ||
x, y, beer = q.popleft() | ||
|
||
if abs(x-fx) + abs(y-fy) <= 50*beer: # ์ถ์ ๊น์ง ๊ฐ ์ ์๋์ง | ||
result = "happy" | ||
break | ||
|
||
for sx, sy in store: # ํธ์์ ๋ค๋ฆด ์ ์๋์ง | ||
if abs(x-sx) + abs(y-sy) <= 50 * beer and (sx, sy) not in visited: | ||
visited.add((sx, sy)) | ||
q.append((sx, sy, 20)) | ||
|
||
if beer > 0: # beer ๋จน๊ณ ๊ฐ๊ธฐ | ||
for i in range(4): | ||
nx = x + dx[i] | ||
ny = y + dy[i] | ||
|
||
if (nx, ny) not in visited: | ||
visited.add((nx, ny)) | ||
q.append((nx, ny, beer - 1)) | ||
|
||
print(result) | ||
|
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,64 @@ | ||
import sys | ||
from collections import deque | ||
|
||
def input() : return sys.stdin.readline().rstrip() | ||
|
||
N = int(input()) | ||
space = [list(map(int, input().split())) for _ in range(N)] | ||
|
||
dir = [(0,1), (0,-1), (1,0), (-1,0)] | ||
x = 0 | ||
y = 0 | ||
|
||
for i in range(N): | ||
for j in range(N): | ||
if space[i][j] == 9: | ||
x, y = i, j | ||
space[x][y] = 0 | ||
|
||
def check(a, b): | ||
if 0<=a<N and 0<=b<N: | ||
return True | ||
return False | ||
|
||
baby = 2 | ||
|
||
time = 0 | ||
fish = 0 | ||
|
||
while True: | ||
q = deque([(x, y, 0)]) | ||
visited = [[False] * N for _ in range(N)] | ||
visited[x][y] = True | ||
min_dis = float('inf') | ||
tmp = [] | ||
|
||
while q: | ||
cx, cy, dis = q.popleft() | ||
|
||
if 0 < space[cx][cy] < baby: | ||
if dis < min_dis: | ||
min_dis = dis | ||
tmp = [(cx, cy)] | ||
elif dis == min_dis: | ||
tmp.append((cx, cy)) | ||
|
||
for dx, dy in dir: | ||
nx, ny = cx + dx, cy + dy | ||
if check(nx, ny) and not visited[nx][ny] and space[nx][ny] <= baby: | ||
visited[nx][ny] = True | ||
q.append((nx, ny, dis + 1)) | ||
|
||
if not tmp: | ||
break | ||
|
||
tx, ty = min(tmp) | ||
space[tx][ty] = 0 | ||
time += min_dis | ||
fish += 1 | ||
if fish == baby: | ||
baby += 1 | ||
fish = 0 | ||
x, y = tx, ty | ||
|
||
print(time) |
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,28 @@ | ||
import sys | ||
import itertools | ||
|
||
def input() : return sys.stdin.readline().rstrip() | ||
|
||
clothes = [["yellow_hat", "headgear"], | ||
["blue_sunglasses", "eyewear"], | ||
["green_turban", "headgear"], | ||
["test1", "sample"], | ||
["test2", "sample"], | ||
] | ||
c_dict = {} | ||
answer = 1 | ||
|
||
for info in range(len(clothes)): | ||
if not clothes[info][1] in c_dict: | ||
c_dict[clothes[info][1]] = 1 | ||
else: | ||
c_dict[clothes[info][1]] += 1 | ||
|
||
# answer = collections.Counter(c_dict) | ||
|
||
for c in c_dict.values(): | ||
answer *= (c+1) | ||
|
||
answer -= 1 | ||
|
||
print(answer) |
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 |
---|---|---|
@@ -1,51 +1,30 @@ | ||
import Foundation | ||
|
||
func solution(_ maps: [[Int]]) -> Int { | ||
var maps = maps | ||
let dx = [-1, 1, 0, 0] | ||
let dy = [0, 0, -1, 1] | ||
let rowCount = maps.count | ||
let colCount = maps[0].count | ||
|
||
func bfs(_ x: Int, _ y: Int) -> Int { | ||
var queue = [(x, y)] | ||
var index = 0 | ||
|
||
while index < queue.count { | ||
let (x, y) = queue[index] | ||
index += 1 | ||
|
||
for i in 0..<4 { | ||
let nx = x + dx[i] | ||
let ny = y + dy[i] | ||
|
||
if nx < 0 || nx >= rowCount || ny < 0 || ny >= colCount { | ||
continue | ||
} | ||
|
||
if maps[nx][ny] == 0 { | ||
continue | ||
} | ||
|
||
if maps[nx][ny] == 1 { | ||
from collections import deque | ||
def solution(maps): | ||
answer = 0 | ||
|
||
dx = [-1, 1, 0, 0] | ||
dy = [0, 0, -1, 1] | ||
|
||
def bfs(x, y): | ||
queue = deque() | ||
queue.append((x, y)) | ||
|
||
while queue: | ||
x, y = queue.popleft() | ||
|
||
for i in range(4): | ||
nx = x + dx[i] | ||
ny = y + dy[i] | ||
|
||
if nx < 0 or nx >= len(maps) or ny < 0 or ny >= len(maps[0]): continue | ||
|
||
if maps[nx][ny] == 0: continue | ||
|
||
if maps[nx][ny] == 1: | ||
maps[nx][ny] = maps[x][y] + 1 | ||
queue.append((nx, ny)) | ||
} | ||
} | ||
} | ||
|
||
return maps[rowCount - 1][colCount - 1] | ||
} | ||
|
||
let answer = bfs(0, 0) | ||
return answer == 1 ? -1 : answer | ||
} | ||
|
||
// ์์ ํธ์ถ | ||
let maps = [ | ||
[1, 0, 1, 1, 1], | ||
[1, 0, 1, 0, 1], | ||
[1, 1, 1, 0, 1], | ||
[0, 0, 0, 0, 1] | ||
] | ||
print(solution(maps)) // ์ถ๋ ฅ: 11 | ||
|
||
return maps[len(maps)-1][len(maps[0])-1] | ||
|
||
answer = bfs(0, 0) | ||
return -1 if answer == 1 else answer |
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,22 @@ | ||
N = int(input()) | ||
tanghuru = list(map(int, input().split())) | ||
fruit = [0] * 10 | ||
kind = 0 | ||
start, end = 0, 0 | ||
|
||
while True: | ||
if end == N: | ||
print(end - start) | ||
break | ||
if fruit[tanghuru[end]] == 0: | ||
kind += 1 | ||
fruit[tanghuru[end]] += 1 | ||
end += 1 | ||
|
||
if kind > 2: | ||
fruit[tanghuru[start]] -= 1 | ||
if fruit[tanghuru[start]] == 0: | ||
kind -= 1 | ||
start += 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import sys | ||
|
||
def input(): return sys.stdin.readline().rstrip() | ||
|
||
N, a, b = map(int, input().split()) | ||
if(N+1<(a+b)): print(-1) | ||
else: | ||
answer = [0 for _ in range(N)] | ||
|
||
if a>b: | ||
for idx, element in enumerate(range(N-a-b+1, N-b+1)): | ||
answer[element] = idx+1 | ||
|
||
for idx, element in enumerate(range(N-1, N-b, -1)): | ||
answer[element] = idx+1 | ||
|
||
for idx in range(N-a-b+1): | ||
answer[idx] = 1 | ||
|
||
else: | ||
for idx, element in enumerate(range(N-b, N)): | ||
answer[element] = b - idx | ||
|
||
for idx, element in enumerate(range(N-b-a+1, N-b)): | ||
answer[element] = idx+1 | ||
|
||
for idx in range(N-b-a+1): | ||
answer[idx] = 1 | ||
|
||
if a == 1: | ||
answer[N-b], answer[0] = answer[0], answer[N-b] | ||
|
||
print(*answer) |
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,22 @@ | ||
import sys | ||
|
||
def input(): return sys.stdin.readline().rstrip() | ||
|
||
A, B = map(int, input().split()) | ||
|
||
bits = [0 for _ in range(len(bin(B)[2:]))] | ||
|
||
for step in range(len(bits)): | ||
one_count_per_bundle = (2**step) | ||
total_count_bundle = 2 * (one_count_per_bundle) | ||
|
||
B_d, B_m = divmod(B,total_count_bundle) | ||
B_count = one_count_per_bundle * B_d | ||
if(B_m >= one_count_per_bundle): B_count += min(one_count_per_bundle,(B_m - one_count_per_bundle + 1)) | ||
|
||
A_d, A_m = divmod(A-1,total_count_bundle) | ||
A_count = one_count_per_bundle * A_d | ||
if(A_m >= one_count_per_bundle): A_count += min(one_count_per_bundle, (A_m - one_count_per_bundle + 1)) | ||
bits[step] += (B_count - A_count) | ||
|
||
print(sum(bits)) |
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,50 @@ | ||
import sys | ||
|
||
def input(): return sys.stdin.readline().rstrip() | ||
|
||
N = int(input()) | ||
building = list(map(int,input().split())) | ||
answer_count = [0 for _ in range(N)] | ||
answer_idx = [int(1e9) for _ in range(N)] | ||
stack = [] | ||
for idx in range(N-1,-1,-1): | ||
now_height = building[idx] | ||
if len(stack) == 0: stack.append((now_height, idx)) | ||
else: | ||
while stack and now_height >= stack[-1][0]: | ||
stack.pop() | ||
|
||
if len(stack) > 0: | ||
if answer_idx[idx] != int(1e9) and abs(answer_idx[idx]-idx) < abs(stack[-1][1] - idx): | ||
stack.append((now_height, idx)) | ||
continue | ||
|
||
answer_idx[idx] = stack[-1][1] | ||
answer_count[idx] += len(stack) | ||
|
||
stack.append((now_height, idx)) | ||
|
||
stack = [] | ||
for idx in range(N): | ||
now_height = building[idx] | ||
if len(stack) == 0: stack.append((now_height, idx)) | ||
else: | ||
while stack and now_height >= stack[-1][0]: | ||
stack.pop() | ||
|
||
if len(stack) > 0: | ||
if answer_idx[idx] != int(1e9) and abs(answer_idx[idx]-idx) < abs(stack[-1][1] - idx): | ||
answer_count[idx] += len(stack) | ||
stack.append((now_height, idx)) | ||
continue | ||
|
||
answer_idx[idx] = stack[-1][1] | ||
answer_count[idx] += len(stack) | ||
|
||
if stack and stack[-1][0] == now_height: continue | ||
|
||
stack.append((now_height, idx)) | ||
|
||
for count, idx in zip(answer_count, answer_idx): | ||
if idx == int(1e9): print(0) | ||
else: print(count, idx+1) |