Skip to content

Commit

Permalink
2024-01-18
Browse files Browse the repository at this point in the history
  • Loading branch information
H0ngJu committed Jan 18, 2025
1 parent 5acb83c commit 9a21107
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
4 changes: 3 additions & 1 deletion H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@
| 34์ฐจ์‹œ | 2024.11.19 | ๋ˆ„์ ํ•ฉ | [๊ฐœ๋˜ฅ๋ฒŒ๋ ˆ](https://www.acmicpc.net/problem/3020) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/256 |
| 35์ฐจ์‹œ | 2024.11.23 | DP | [์ „๊นƒ์ค„](https://www.acmicpc.net/problem/2565) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/258 |
| 36์ฐจ์‹œ | 2024.12.02 | ์ˆ˜ํ•™ | [๋จธ๋ฆฌ ํ†กํ†ก](https://www.acmicpc.net/problem/1241) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/260 |
| 36์ฐจ์‹œ | 2024.12.31 | ๊ทธ๋ฆฌ๋”” | [ํšŒ์˜์‹ค ๋ฐฐ์ •](https://www.acmicpc.net/problem/1931) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/261 |
| 37์ฐจ์‹œ | 2024.12.31 | ๊ทธ๋ฆฌ๋”” | [ํšŒ์˜์‹ค ๋ฐฐ์ •](https://www.acmicpc.net/problem/1931) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/262 |
| 38์ฐจ์‹œ | 2024.01.06 | ์ •๋ ฌ | [์ตœ์†Œ ํšŒ์˜์‹ค ๊ฐœ์ˆ˜](https://www.acmicpc.net/problem/19598) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/263 |
| 39์ฐจ์‹œ | 2024.01.18 | ์ •๋ ฌ | [์ปฌ๋Ÿฌ๋ณผ](https://www.acmicpc.net/problem/10800) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/266 |
57 changes: 57 additions & 0 deletions H0ngJu/๋ˆ„์ ํ•ฉ/์ปฌ๋Ÿฌ๋ณผ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())
info = [list(map(int, input().split())) + [i] for i in range(N)]
dp = [0 for _ in range(N)]
answer = [0 for _ in range(N)]

# ์™„ํƒ -> ์‹œ๊ฐ„ ์ดˆ๊ณผ
# a๊ฐ€ b๋ณด๋‹ค ํฌ๋ฉด (์ƒ‰์ด ๋‹ค๋ฅด๋‹ค๋Š” ๊ฐ€์ • ํ•˜์—), a๋Š” b ๊ฐ’์„ + ํ•˜๋ฉด ๋จ -> ๋ˆ„์ ํ•ฉ -> ์ „์ฒด ๊ฐ’์—์„œ ๊ฐ™์€ ์ƒ‰๋งŒ ๋นผ์ฃผ๊ธฐ

info.sort(key=lambda x: (x[1], x[0]))
total = 0
color_sum = [0 for _ in range(200001)]
size_sum = [0 for _ in range(200001)]
pre_size = 0 # ๋‹ค๋ฅธ ์ปฌ๋Ÿฌ์ด๋ฉด์„œ ๊ฐ™์€ ์‚ฌ์ด์ฆˆ์ธ ๊ฒฝ์šฐ๋ฅผ ์œ„ํ•ด ์ €์žฅ
pre_color = 0

for i in range(N):
color, size, index = info[i]

if pre_color == color and pre_size == size:
dp[index] = dp[info[i-1][2]]
else :
dp[index] = total - color_sum[color] - size_sum[size]

total += size
color_sum[color] += size # ๊ฐ™์€ ์ƒ‰๊น”์˜ ํ•ฉ
size_sum[size] += size # ๊ฐ™์€ ์‚ฌ์ด์ฆˆ์˜ ํ•ฉ

pre_size = size
pre_color = color

for i in dp:
print(i)

# ์˜ˆ์™ธ ์ผ€์ด์Šค
# 3
# 1 4
# 2 4
# 1 4

# 6
# 1 5
# 2 6
# 7 6
# 5 6
# 2 6
# 1 6

# 5
# 3 15
# 3 15
# 3 5
# 1 15
# 2 10

0 comments on commit 9a21107

Please sign in to comment.