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

38-9kyo-hwang #148

Merged
merged 3 commits into from
Apr 30, 2024
Merged

38-9kyo-hwang #148

merged 3 commits into from
Apr 30, 2024

Conversation

9kyo-hwang
Copy link
Collaborator

@9kyo-hwang 9kyo-hwang commented Mar 25, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

8980 ํƒ๋ฐฐ

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

1์‹œ๊ฐ„ ๋„˜๊ธฐ๊ณ  ๋ธ”๋กœ๊ทธ๋ฅผ ๋ด๋ฒ„๋ ธ๋‹ค...ใ…œ

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

1. ๋ฌธ์ œ

image
์œ„ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ๋ณธ๋ถ€์—์„œ ์ถœ๋ฐœํ•˜์—ฌ 1๋ฒˆ ๋งˆ์„๋ถ€ํ„ฐ ๋งˆ์ง€๋ง‰ ๋งˆ์„๊นŒ์ง€ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๊ฐ€๋ฉด์„œ ๋งˆ์„์— ์žˆ๋Š” ๋ฌผ๊ฑด์„ ๋ฐฐ์†กํ•œ๋‹ค. ๊ฐ ๋งˆ์„์€ ๋ฐฐ์†กํ•  ๋ฌผ๊ฑด๋“ค์„ ๋ฐ•์Šค์— ๋„ฃ์–ด ๋ณด๋‚ด๋ฉฐ, ๋ณธ๋ถ€์—์„œ๋Š” ๋ฐ•์Šค๋ฅผ ๋ณด๋‚ด๋Š” ๋งˆ์„๋ฒˆํ˜ธ, ๋ฐ•์Šค๋ฅผ ๋ฐ›๋Š” ๋งˆ์„๋ฒˆํ˜ธ์™€ ๋ณด๋‚ผ ๋ฐ•์Šค์˜ ๊ฐœ์ˆ˜๋ฅผ ์•Œ๊ณ  ์žˆ๋‹ค.
์šฉ๋Ÿ‰ ์ œํ•œ์ด ์žˆ๋Š” ์ด ํŠธ๋Ÿญ ํ•œ ๋Œ€๋ฅผ ์ด์šฉํ•ด ๋‹ค์Œ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•ด์•ผ ํ•  ๋•Œ,

  • ๋ฐ•์Šค๋ฅผ ํŠธ๋Ÿญ์— ์‹ค์œผ๋ฉด, ์ด ๋ฐ•์Šค๋Š” ๋ฐ›๋Š” ๋งˆ์„์—์„œ๋งŒ ๋‚ด๋ฆฐ๋‹ค.
  • ํŠธ๋Ÿญ์€ ์ง€๋‚˜์˜จ ๋งˆ์„๋กœ ๋˜๋Œ์•„๊ฐ€์ง€ ์•Š๋Š”๋‹ค.
  • ๋ฐ•์Šค๋“ค ์ค‘ ์ผ๋ถ€๋งŒ ๋ฐฐ์†กํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

๋ฐฐ์†กํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€ ๋ฐ•์Šค ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ.

2. ์‹œํ–‰์ฐฉ์˜ค

๋ฌธ์ œ ์„ค๋ช…์— ์žˆ๋Š” ์˜ˆ์‹œ๋ฅผ ๋ณด๊ณ  "๊ฐ ๋งˆ์„์— ์žˆ๋Š” ํƒ๋ฐฐ๋ฅผ ๊ฐ€๋Šฅํ•œ ๋งŽ์ด ๋‹ด๋„๋ก ํ•˜๋ฉด ๋˜๋Š”๊ฑด๊ฐ€?" ์‹ถ์–ด์„œ ๊ทธ๋ ‡๊ฒŒ ์ž‘์„ฑํ•ด๋ดค๋Š”๋ฐ ๋ฐ”๋กœ 2๋ฒˆ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์—์„œ ๋น ๊พธ๋จน์—ˆ๋‹ค.

ํŠธ๋Ÿญ ์šฉ๋Ÿ‰์ด 60์ด๊ณ  ํƒ๋ฐฐ ์ •๋ณด๊ฐ€ ์•„๋ž˜์™€ ๊ฐ™์„ ๋•Œ

๋ณด๋‚ด๋Š” ๋งˆ์„ ๋ฐ›๋Š” ๋งˆ์„ ๋ฐ•์Šค ๊ฐœ์ˆ˜
1 2 30
1 6 40
2 5 70
3 4 40
5 6 60

๋งˆ์„์— ๋„์ฐฉํ•  ๋•Œ๋งˆ๋‹ค ๊ฐ€๋Šฅํ•œ ๋งŽ์ด ๋‹ด์„ ๊ฒฝ์šฐ

  • 1๋ฒˆ ๋งˆ์„์—์„œ (2, 30), (6, 30) ๋‹ด์Œ -> +60
  • 2๋ฒˆ ๋งˆ์„์—์„œ (2, 30) ๋‚ด๋ฆฌ๊ณ  (5, 30) ๋‹ด์Œ -> +30
  • 3๋ฒˆ ๋งˆ์„์—์„œ๋Š” ์šฉ๋Ÿ‰ ๋ถ€์กฑ์œผ๋กœ ๋ชป๋‹ด์Œ
  • 4๋ฒˆ ๋งˆ์„์—์„œ๋Š” ๋‹ด์„ ๊ฒƒ๋„ ๋‚ด๋ฆด ๊ฒƒ๋„ ์—†์Œ
  • 5๋ฒˆ ๋งˆ์„์—์„œ (5, 30) ๋‚ด๋ฆฌ๊ณ  (6, 30) ๋‹ค์Œ -> +30
  • 6๋ฒˆ ๋งˆ์„์—์„œ (6, 30), (6, 30) ๋‚ด๋ฆผ

๊ณผ ๊ฐ™์€ ํ”„๋กœ์„ธ์Šค๋กœ 120์ด์ง€๋งŒ ๋‹ต์€ 150์ด๋‹ค. ์ด 150์ด๋ž€ ์ˆซ์ž๋Š” ์–ด๋–ป๊ฒŒ ๋‚˜์˜จ ๊ฑธ๊นŒ?

3. ํ’€์ด

์ถœ๋ฐœ ๋งˆ์„ S์—์„œ ๋„์ฐฉ ๋งˆ์„ E๋กœ ๋ฌด๊ฒŒ W์งœ๋ฆฌ ํƒ๋ฐฐ๋ฅผ ๋ฐฐ๋‹ฌํ•˜๋ ค๋ฉด (S, S + 1, S + 2, ..., E - 1)๊นŒ์ง€ ํ•ด๋‹น ๋ฐ•์Šค๋ฅผ ๊ณ„์† ๋“ค๊ณ  ์žˆ์–ด์•ผ ํ•œ๋‹ค. ์ฆ‰ ํŠธ๋Ÿญ์˜ ๊ธฐ๋ณธ ์—ฌ์œ  ์šฉ๋Ÿ‰ C์—์„œ W๋งŒํผ ๋น ์ง„ (C - W)๊ฐ€ ์ž”์—ฌ ์—ฌ์œ  ์šฉ๋Ÿ‰์ด ๋œ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด C = 40์ด๊ณ  ์ด 6๊ฐœ์˜ ๋งˆ์„์ด ์žˆ์„ ๋•Œ, ๋ฌด๊ฒŒ W = 20์งœ๋ฆฌ ๋ฐ•์Šค๋ฅผ S = 2 ๋งˆ์„์—์„œ E = 4 ๋งˆ์„๋กœ ๋ฐฐ๋‹ฌํ•œ๋‹ค๊ณ  ํ•˜๋ฉด

1  2  3  4  5  6   # ๋งˆ์„
40 20 20 40 40 40  # ๊ฐ ๋งˆ์„์—์„œ ํŠธ๋Ÿญ ์—ฌ์œ ์šฉ๋Ÿ‰

์ด๋ ‡๊ฒŒ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ทธ๋ ‡๋‹ค๋ฉด, ํ•œ ๋ฐ•์Šค๊ฐ€ ์ €๋ ‡๊ฒŒ ๊ธธ๊ฒŒ ํŠธ๋Ÿญ ํ•œ ๊ณต๊ฐ„์„ ์ฐจ์ง€ํ•˜์ง€ ์•Š๋„๋ก ํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ• ๊นŒ? ๋‹ต์€ ๋„์ฐฉ ๋งˆ์„์ด ๋น ๋ฅธ ์ˆœ์œผ๋กœ ํƒ๋ฐฐ๋ฅผ ์‹ค์–ด๋ณด๋Š” ๊ฒƒ์ด๋‹ค.

๋‹ค์‹œ ์œ„์˜ ์˜ˆ์‹œ๋ฅผ ๋ณด์ž. ํŠธ๋Ÿญ ์šฉ๋Ÿ‰์ด 60์ด๊ณ  ํƒ๋ฐฐ ์ •๋ณด๊ฐ€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค. ๋‹จ, ์ด๋ฒˆ์—๋Š” ๋„์ฐฉ ๋งˆ์„์ด ๋น ๋ฅธ ์ˆœ์œผ๋กœ ๋ณธ๋‹ค. ๋„์ฐฉ ๋งˆ์„์ด ๊ฐ™๋‹ค๋ฉด ์ถœ๋ฐœ ๋งˆ์„์ด ๋น ๋ฅธ ์ˆœ์ด๋‹ค.

๋ณด๋‚ด๋Š” ๋งˆ์„ ๋ฐ›๋Š” ๋งˆ์„ ๋ฐ•์Šค ๊ฐœ์ˆ˜
1 2 30
3 4 40
2 5 70
1 6 40
5 6 60

์ตœ์ดˆ์—๋Š” ๊ฐ ๋งˆ์„ ๋ณ„ ํŠธ๋Ÿญ ์—ฌ์œ  ์šฉ๋Ÿ‰์ด ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค

1  2  3  4  5  6
60 60 60 60 60 60

๋จผ์ €, 1๋ฒˆ ๋งˆ์„์—์„œ 2๋ฒˆ ๋งˆ์„๋กœ ๋ณด๋‚ด๋Š” 30์งœ๋ฆฌ ํƒ๋ฐฐ๋ฅผ ์‹ค์–ด๋ณธ๋‹ค.
2๋ฒˆ ๋งˆ์„์—์„œ ํƒ๋ฐฐ๋ฅผ ๋‚ด๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์— 2๋ฒˆ ๋งˆ์„์˜ ์—ฌ์œ  ์šฉ๋Ÿ‰์€ ๋ณ€ํ•˜์ง€ ์•Š๋Š”๋‹ค.

1  2  3  4  5  6
30 60 60 60 60 60 

์—ฌ๊ธฐ์„œ 30๋งŒํผ ์‹ค์„ ์ˆ˜ ์žˆ๋‹ค.

๋‹ค์Œ์œผ๋กœ 3๋ฒˆ ๋งˆ์„ -> 4๋ฒˆ ๋งˆ์„ ํƒ๋ฐฐ๋ฅผ ์‹ค์–ด๋ณธ๋‹ค.

1  2  3  4  5  6
30 60 20 60 60 60

์—ฌ๊ธฐ์„œ 40๋งŒํผ ์‹ค์„ ์ˆ˜ ์žˆ๋‹ค.

๋‹ค์Œ์€ 2๋ฒˆ -> 5๋ฒˆ ํƒ๋ฐฐ๋‹ค.
์ด์ „ ํƒ๋ฐฐ๋กœ ์ธํ•ด 3๋ฒˆ ๋งˆ์„์—์„œ ์ตœ๋Œ€ ์šฉ๋Ÿ‰ ์ œํ•œ์ด 20์ด๊ธฐ ๋•Œ๋ฌธ์—, 2๋ฒˆ ๋งˆ์„์—์„œ 5๋ฒˆ ๋งˆ์„ ๊ฐ€๋Š” ๋™์•ˆ์—๋Š” 20๋ฐ–์— ๋ชป์‹ค๋Š”๋‹ค.

1  2  3  4  5  6
30 40 0  40 60 60 

์—ฌ๊ธฐ์„œ 20๋งŒํผ ์‹ค์„ ์ˆ˜ ์žˆ๋‹ค.

๋‹ค์Œ์€ 1๋ฒˆ -> 6๋ฒˆ์ด๋‹ค.
์ด์ „ ํƒ๋ฐฐ๋“ค๋กœ ์ธํ•ด 3๋ฒˆ ๋งˆ์„์„ ์ง€๋‚˜๊ฐˆ ๋•Œ๋Š” ๋ฐ•์Šค๋ฅผ ์•„์˜ˆ ์‹ค์„ ์ˆ˜ ์—†๋‹ค. ๋”ฐ๋ผ์„œ ์ด ํƒ๋ฐฐ๋Š” ์‹ค์„ ์ˆ˜ ์—†๋‹ค.

1  2  3  4  5  6
30 40 0  40 60 60 

๋งˆ์ง€๋ง‰์œผ๋กœ 5๋ฒˆ -> 6๋ฒˆ์ด๋‹ค.
์•ž์„  ํƒ๋ฐฐ๋ฅผ ๋ณด๋‚ด๋Š” ๊ฒฝ๋กœ๋ž‘ ๊ฒน์น˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์‹ค์„ ์ˆ˜ ์žˆ๋‹ค.

1  2  3  4  5  6
30 40 0  40 0  60 

์—ฌ๊ธฐ์„œ 60๋งŒํผ ์‹ค์„ ์ˆ˜ ์žˆ๋‹ค.

์ตœ์ข…์ ์œผ๋กœ 30 + 40 + 20 + 60 = 150๋งŒํผ ์‹ค๋Š”๋‹ค. ์ด ๊ฒฝ์šฐ๊ฐ€ ์ตœ๋Œ€์ด๋‹ค. ์ด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ฝ”๋“œ๋กœ ๊ตฌํ˜„ํ•ด๋ณด์ž.

4. ๊ตฌํ˜„

N, C = map(int, input().split())  # ๋งˆ์„ ์ˆ˜, ํŠธ๋Ÿญ ์šฉ๋Ÿ‰
M = int(input())  # ๋ฐ•์Šค ์ •๋ณด ์ˆ˜
boxes = [tuple(map(int, input().split())) for _ in range(M)]  # ์‹œ์ž‘ ๋งˆ์„, ๋„์ฐฉ ๋งˆ์„, ๋ฐ•์Šค ๊ฐœ์ˆ˜
boxes.sort(key=lambda x: (x[1], x[0]))  # ๋„์ฐฉ ๋งˆ์„ ๋น ๋ฅธ ์ˆœ, ์‹œ์ž‘ ๋งˆ์„ ๋น ๋ฅธ ์ˆœ์œผ๋กœ ์ •๋ ฌ

์ •๋ณด๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. ์œ„์—์„œ ์–˜๊ธฐํ•œ ๋Œ€๋กœ ํƒ๋ฐฐ ์ •๋ณด๋ฅผ ๋„์ฐฉ ๋งˆ์„ ๋น ๋ฅธ ์ˆœ -> ์‹œ์ž‘ ๋งˆ์„ ๋น ๋ฅธ ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค.

remain_spaces = [C] * (N + 1)  # ๊ฐ ๋งˆ์„ ๋ณ„ ํŠธ๋Ÿญ์— ์‹ค์„ ์ˆ˜ ์žˆ๋Š” ๊ณต๊ฐ„

๊ฐ ๋งˆ์„์—์„œ ํŠธ๋Ÿญ์— ์‹ค์„ ์ˆ˜ ์žˆ๋Š” ์—ฌ์œ  ๊ณต๊ฐ„์„ ๊ธฐ๋กํ•˜๋Š” ๋ฆฌ์ŠคํŠธ์ด๋‹ค. ์ตœ์ดˆ์—๋Š” ์ตœ๋Œ€ ์šฉ๋Ÿ‰์ธ C์ด๋‹ค.

ans = 0
for src, dst, box in boxes:
    min_remain_space = min(remain_spaces[src:dst])  # ์ง€๋‚˜๊ฐ€๋Š” ๊ตฌ๊ฐ„ ์ค‘ ๊ฐ€์žฅ ์ ์€ ์—ฌ์œ  ๊ณต๊ฐ„
    carriable_capacity = min(box, min_remain_space)  # ํŠธ๋Ÿญ์— ์ถ”๊ฐ€๋กœ ์‹ค์„ ์ˆ˜ ์žˆ๋Š” ํƒ๋ฐฐ ๊ฐœ์ˆ˜.
    remain_spaces[src:dst] = [x - carriable_capacity for x in remain_spaces[src:dst]]
    ans += carriable_capacity

์ •๋ ฌ๋œ ๋ฐ•์Šค ์ •๋ณด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํƒ๋ฐฐ ๋ฐฐ์†ก์„ ์‹œ์ž‘ํ•œ๋‹ค. ํ•œ ์ค„์”ฉ ํ™•์ธํ•ด๋ณด์ž.

min_remain_space = min(remain_spaces[src:dst])  # ์ง€๋‚˜๊ฐ€๋Š” ๊ตฌ๊ฐ„ ์ค‘ ๊ฐ€์žฅ ์ ์€ ์—ฌ์œ  ๊ณต๊ฐ„

์‹œ์ž‘ ๋งˆ์„ ~ ๋„์ฐฉ ๋งˆ์„ ์‚ฌ์ด์— ํŠธ๋Ÿญ์ด ๊ฐ€์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์šฉ๋Ÿ‰ ์ค‘ ๊ฐ€์žฅ ์ ์€ ์šฉ๋Ÿ‰์„ ๊ตฌํ•œ๋‹ค. ์œ„ ์„ค๋ช…์—์„œ 2๋ฒˆ ๋งˆ์„ -> 5๋ฒˆ ๋งˆ์„ ํƒ๋ฐฐ ์„ค๋ช…์„ ๋‹ค์‹œ ํ™•์ธํ•ด๋ณด์ž.

1  2  3  4  5  6
30 60 20 60 60 60
30 40 0  40 60 60 

์•ž์„  ํƒ๋ฐฐ๋“ค๋กœ ์ธํ•ด 3๋ฒˆ ๋งˆ์„์—์„œ ์ตœ๋Œ€ ์šฉ๋Ÿ‰ ์ œํ•œ์ด 20์ด๊ธฐ ๋•Œ๋ฌธ์—, 2๋ฒˆ ๋งˆ์„์—์„œ 5๋ฒˆ ๋งˆ์„ ๊ฐ€๋Š” ๋™์•ˆ์—๋Š” 20๋ฐ–์— ๋ชป์‹ค๋Š”๋‹ค.
์ด ๋ถ€๋ถ„์— ํ•ด๋‹นํ•˜๋Š” ์ฝ”๋“œ์ด๋‹ค.

carriable_capacity = min(box, min_remain_space)

ํ•ด๋‹น ๊ตฌ๊ฐ„์—์„œ ํŠธ๋Ÿญ์ด ๊ฐ€์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์šฉ๋Ÿ‰๊ณผ ๋ฐ•์Šค ๋ฌด๊ฒŒ ์ค‘ ์ž‘์€ ๊ฐ’์ด ์‹ค์ œ๋กœ ์˜ฎ๊ธธ ์ˆ˜ ์žˆ๋Š” ์šฉ๋Ÿ‰์ด ๋œ๋‹ค.

remain_spaces[src:dst] = [x - carriable_capacity for x in remain_spaces[src:dst]]

์œ„ ์„ค๋ช…๋Œ€๋กœ, ํƒ๋ฐฐ๋ฅผ ์ถ”๊ฐ€๋กœ ์‹ค์—ˆ์œผ๋‹ˆ ํ•ด๋‹น ๊ตฌ๊ฐ„์—์„œ ํŠธ๋Ÿญ์ด ๊ฐ€์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์šฉ๋Ÿ‰๋„ ์ด๋ฒˆ์— ์‹ค์€ ํƒ๋ฐฐ ๋ฌด๊ฒŒ๋งŒํผ ์ค„์—ฌ์ค€๋‹ค.

ans += carriable_capacity

์ด๋ฒˆ์— ์ƒˆ๋กœ ์‹ค์€ ํƒ๋ฐฐ ๋ฌด๊ฒŒ๋ฅผ ans์— ๋”ํ•ด์ค€๋‹ค.

print(ans)

๋งˆ์ง€๋ง‰์œผ๋กœ ๊ธฐ๋กํ•œ ๋ฌด๊ฒŒ๋“ค์„ ์ถœ๋ ฅํ•ด์ฃผ๋ฉด ์™„์„ฑ์ด๋‹ค.

5. ์ „์ฒด ์ฝ”๋“œ

  • ํŒŒ์ด์ฌ
input = open(0).readline

N, C = map(int, input().split())  # ๋งˆ์„ ์ˆ˜, ํŠธ๋Ÿญ ์šฉ๋Ÿ‰
M = int(input())  # ๋ฐ•์Šค ์ •๋ณด ์ˆ˜
boxes = [tuple(map(int, input().split())) for _ in range(M)]  # ์‹œ์ž‘ ๋งˆ์„, ๋„์ฐฉ ๋งˆ์„, ๋ฐ•์Šค ๊ฐœ์ˆ˜
boxes.sort(key=lambda x: (x[1], x[0]))  # ๋„์ฐฉ ๋งˆ์„ ๋น ๋ฅธ ์ˆœ, ์‹œ์ž‘ ๋งˆ์„ ๋น ๋ฅธ ์ˆœ์œผ๋กœ ์ •๋ ฌ

remain_spaces = [C] * (N + 1)  # ๊ฐ ๋งˆ์„ ๋ณ„ ํŠธ๋Ÿญ์— ์‹ค์„ ์ˆ˜ ์žˆ๋Š” ๊ณต๊ฐ„

ans = 0
for src, dst, box in boxes:
    min_remain_space = min(remain_spaces[src:dst])  # ์ง€๋‚˜๊ฐ€๋Š” ๊ตฌ๊ฐ„ ์ค‘ ๊ฐ€์žฅ ์ ์€ ์—ฌ์œ  ๊ณต๊ฐ„
    carriable_capacity = min(box, min_remain_space)  # ํŠธ๋Ÿญ์— ์ถ”๊ฐ€๋กœ ์‹ค์„ ์ˆ˜ ์žˆ๋Š” ํƒ๋ฐฐ ๊ฐœ์ˆ˜.
    remain_spaces[src:dst] = [x - carriable_capacity for x in remain_spaces[src:dst]]
    ans += carriable_capacity

print(ans)
  • C++
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

int main()
{
    int N, C, M; cin >> N >> C >> M;
    vector<tuple<int, int, int>> Boxes(M);
    for(auto& [Dst, Src, Box] : Boxes)
    {
        cin >> Src >> Dst >> Box;
    }
    sort(Boxes.begin(), Boxes.end());
    
    vector<int> RemainSpaces(N + 1, C);
    
    int Answer = 0;
    for(const auto& [Dst, Src, Box] : Boxes)
    {
        int MinRemainSpace = C;
        for(int i = Src; i < Dst; ++i)
        {
            MinRemainSpace = min(MinRemainSpace, RemainSpaces[i]);
        }
        int LoadableBox = min(Box, MinRemainSpace);
        
        Answer += LoadableBox;
        for(int i = Src; i < Dst; ++i)
        {
            RemainSpaces[i] -= LoadableBox;
        }
    }
    cout << Answer;
    return 0;
}

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

์ž˜๋ชป๋œ ์ ‘๊ทผ์—์„œ ๋ฒ—์–ด๋‚˜์ง€ ๋ชปํ•˜๊ณ ... ์‚ฝ์งˆ๋งŒ ์‹ค์ปท ํ•˜๋‹ค๊ฐ€ ๊ฒฐ๊ตญ ๋ธ”๋กœ๊ทธ ๋ด๋ฒ„๋ ธ๋‹ค ใ…œ
์ด ๋ฌธ์ œ ๋„ˆ๋ฌด ์–ด๋ ต๋„ค...

์•ฝ๊ฐ„ ๊ทธ ๊ฐ•์˜์‹ค ๋ฐฐ์ • ๋ฌธ์ œ๋ž‘ ๋น„์Šทํ•œ ์ ‘๊ทผ๊ฐ™๊ธฐ๋„ ํ•˜๊ณ ...?

Copy link
Member

@gjsk132 gjsk132 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฌธ์ œ ์ฝ๊ณ  ์ด์ „ ๊ฐ•์˜์‹ค ๋ฌธ์ œ๋ž‘ ๋น„์Šทํ•ด์„œ ๋‚˜๋ฆ„ ์‰ฝ๊ฒŒ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค!

ํž™ ์ผ๋‹ค๊ฐ€ 15%์— ๋ง‰ํžˆ๊ณ , ๋ญ์ง€ ์™œ ์•ˆ๋˜์ง€ ํ•ด์„œ ํƒ๋ฐฐ๋ฅผ ์‹ค์–ด๊ฐ€๋Š” ๊ฑฐ๋ฆฌ๋ณ„๋กœ ์ฒดํฌํ–ˆ๋Š”๋ฐ๋„ ๋ง‰ํžˆ๊ณ ๋ฅผ ๋ฐ˜๋ณตํ•˜๋‹ค ๊ทธ๋ƒฅ PR ํ™•์ธํ•˜๊ณ ๋„ ๋˜‘๊ฐ™๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋Š”๋ฐ...

๊ทธ๋ƒฅ ์ œ๊ฐ€ ๋จผ์ € ๋๋‚˜๋Š” ๊ฑฐ ์šฐ์„ ์œผ๋กœ ์ •๋ ฌํ•ด์•ผํ•˜๋Š”๋ฐ ์ž˜๋ชป ์ •๋ ฌํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค. ๐Ÿฅฒ

์•ฝ๊ฐ„ ๋‹ค๋ฅธ ๋ถ€๋ถ„์ด ์˜ฎ๊ธฐ๋Š” ํƒ๋ฐฐ๊ฐ€ 0๊ฐœ๋ผ๋ฉด ์ดํ›„์˜ ๋ฐ˜๋ณตํ•ด์„œ ๋นผ์ฃผ๋Š” ๊ณผ์ •์„ ์—†์• ์คฌ์Šต๋‹ˆ๋‹ค!

if (can_move:= min(min(left_move[start:end]), boxes)) == 0:
    continue

@gjsk132
Copy link
Member

gjsk132 commented Apr 15, 2024

remain_spaces[src:dst] = [x - carriable_capacity for x in remain_spaces[src:dst]]

์–ด๋–ป๊ฒŒ ๋งˆ์„๋งˆ๋‹ค ๋นผ์ค˜์•ผํ•˜์ง€ ์•ฝ๊ฐ„ ๊ณ ๋ฏผํ–ˆ์—ˆ๋Š”๋ฐ ์ด๋ ‡๊ฒŒ๋„ ๊ฐ€๋Šฅํ•˜๊ตฐ์š”


python
boxes.sort(key=lambda x: (x[1], x[0]))

c++
sort(Boxes.begin(), Boxes.end());

์ด๊ฑฐ ์ €๋ฒˆ์— ํšŒ์˜์‹ค ๋ฌธ์ œ์—์„œ๋„ ๋ณธ ๊ฒƒ ๊ฐ™์€๋ฐ, ๋๋‚˜๋Š” ์ง€์ , ์‹œ์ž‘ ์ง€์ , ๊ฑฐ๋ฆฌ๋กœ ๋„ฃ์–ด์„œ ์ •๋ ฌํ•˜๋ฉด ๋ฐ”๋กœ ๋์—ˆ๋„ค์š”..!

Copy link
Member

@xxubin04 xxubin04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ตœ๋Œ€ํ•œ ๋งŽ์€ ํƒ๋ฐฐ ๋ฐ•์Šค๋ฅผ ๋ฐฐ์†กํ•˜๊ธฐ ์œ„ํ•ด์„œ, ๋„์ฐฉ ๋งˆ์„์ด ๋น ๋ฅธ ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋Š”๊ฒŒ ์•„ํ•˜ํฌ์ธํŠธ์˜€์Šต๋‹ˆ๋‹ค.
์ €๋„ ์ฒ˜์Œ์—๋Š” ๋‹น์—ฐํ•˜๊ฒŒ ๋ณด๋‚ด๋Š” ๋งˆ์„์„ ๊ธฐ์ค€์œผ๋กœ ์ƒ๊ฐํ–ˆ์—ˆ๋Š”๋ฐ, ์–ด๋–ค ๊ธฐ์ค€์œผ๋กœ ์ƒ๊ฐํ•˜๋Š๋ƒ์— ๋”ฐ๋ผ ๋‚˜์˜ค๋Š” ๊ฐ’์ด ๋‹ฌ๋ผ์ง€๋„ค์š”.. ์–ด๋ ต์Šต๋‹ˆ๋‹ค..๐Ÿฅน

 remain_spaces[src:dst] = [x - carriable_capacity for x in remain_spaces[src:dst]]

์ฒ˜์Œ์— ์ด ์ฝ”๋“œ ๋ถ€๋ถ„์ด ์ดํ•ดํ•˜๊ธฐ ์กฐ๊ธˆ ์–ด๋ ค์› ๋Š”๋ฐ, ๊ฐ๊ฐ์˜ ๋งˆ์„์—์„œ ์ด๋ฒˆ์— ์‹ค์€ ํƒ๋ฐฐ ๋ฌด๊ฒŒ๋ฅผ ๋นผ์ฃผ๋Š” ์ฝ”๋“œ๊ตฐ์š”!
์ด๋ ‡๊ฒŒ ํ•œ ์ค„๋กœ๋„ ์“ธ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค~~๐Ÿ‘

@9kyo-hwang 9kyo-hwang merged commit 57b6640 into main Apr 30, 2024
6 checks passed
@9kyo-hwang 9kyo-hwang deleted the 38-9kyo-hwang branch April 30, 2024 08:48
Copy link
Collaborator

@Dolchae Dolchae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์กฐ๊ฑด์ด ์—ฌ๋Ÿฌ ๊ฐœ์ธ ๋ฌธ์ œ๋ฅผ ๋ถ„์„ํ•˜๊ณ  ๊ทธ๊ฑธ ํ•œ๋ฒˆ์— ๋”ฑ ์ •๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ์•„์ด๋””์–ด ์ฐพ๋Š” ๊ฒŒ ์ •๋ง ์–ด๋ ต๊ฒŒ ๋Š๊ปด์ง€๋Š” ๊ฒƒ ๊ฐ™์•„์š”. ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค๐Ÿ˜Š

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants