Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11-fnzksxl #56

Merged
merged 3 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fnzksxl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
| 7์ฐจ์‹œ | 2024-02-18 | ๊ทธ๋ฆฌ๋”” | [๊ตฌ๋ช…๋ณดํŠธ](https://school.programmers.co.kr/learn/courses/30/lessons/42885) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/30) |
| 8์ฐจ์‹œ | 2024-02-20 | DP | [๋™์ „1](https://www.acmicpc.net/problem/2293) | [#32](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/32) |
| 9์ฐจ์‹œ | 2024-02-23 | ๊ทธ๋ž˜ํ”„ | [์ˆœ์œ„](https://school.programmers.co.kr/learn/courses/30/lessons/49191) | [#37](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/37) |
| 10์ฐจ์‹œ | 2024-03-07 | ๊ตฌํ˜„ | [๋‚˜๋ฌด ์žฌํ…Œํฌ](https://www.acmicpc.net/problem/16235) | [#52](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/52) |
| 11์ฐจ์‹œ | 2024-03-10 | ํˆฌํฌ์ธํ„ฐ | [๋ณด์„ ์‡ผํ•‘](https://school.programmers.co.kr/learn/courses/30/lessons/67258) | [#56](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/56) |
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import sys

dx = [-1, -1, 0, 1, 1, 1, 0, -1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]

input = sys.stdin.readline


def whole_year():
def push_trees(tree):
if not (age + 1) % 5:
for d in range(8):
nx = i + dx[d]
ny = j + dy[d]
if nx >= 0 and nx < N and ny >= 0 and ny < N:
new_tree.append((nx, ny, tree))

new_tree = []
for i in range(N):
for j in range(N):
if trees[i][j]: # ๋นˆ ๋”•์…”๋„ˆ๋ฆฌ๋ฉด ๊ทธ๋ƒฅ ํ†ต๊ณผ
dead_trees = 0
alive = {}
OKAY = True # ํ† ์–‘์ด ๋‚˜๋ฌด๋“ค์„ ์„ฑ์žฅ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š”์ง€ ์—†๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ ํ”Œ๋ž˜๊ทธ
for age in sorted(trees[i][j]): # ์–ด๋ฆฐ ๋‚˜๋ฌด๋ถ€ํ„ฐ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ๋”•์…”๋„ˆ๋ฆฌ ์ •๋ ฌ
if OKAY:
if age * trees[i][j][age] > bat[i][j]:
survive = bat[i][j] // age
if survive:
bat[i][j] -= survive * age
alive[age+1] = survive
push_trees(survive)
dead_trees += (trees[i][j][age] - survive) * (age // 2)
OKAY = False
else:
bat[i][j] -= age * trees[i][j][age]
alive[age+1] = trees[i][j][age]
push_trees(trees[i][j][age])
else:
dead_trees += trees[i][j][age] * (age // 2)

bat[i][j] += dead_trees
trees[i][j] = alive

bat[i][j] += yang[i][j]

for x, y, tree in new_tree:
if 1 in trees[x][y].keys():
trees[x][y][1] += tree
else:
trees[x][y][1] = tree
# trees[x][y][1] = trees[x][y].get(1, 0) + tree


N, M, K = map(int, input().split())

answer = 0
yang = [list(map(int, input().split())) for _ in range(N)]
bat = [[5]*N for _ in range(N)]
trees = [[{} for _ in range(N)] for _ in range(N)]

for _ in range(M):
x, y, z = map(int, input().split())
trees[x-1][y-1][z] = 1


for _ in range(K):
whole_year()

for i in range(N):
for j in range(N):
answer += sum(trees[i][j].values())

print(answer)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def solution(gems):
answer = []
head, tail = 0, 0
gem_length = len(set(gems))
gems_dict = {}
gem_min = len(gems) + 1

while head <= tail < len(gems):
gems_dict[gems[tail]] = gems_dict.get(gems[tail], 0) + 1
tail+=1

if len(gems_dict) == gem_length:
while head < tail:
if gems_dict[gems[head]] > 1:
gems_dict[gems[head]] -= 1
head += 1

elif gem_min > tail - head:
gem_min = tail - head
answer = [head+1, tail]
break

else:
break

return answer
Loading