Skip to content

1011. Capacity To Ship Packages Within D Days #45

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fhiyo
Copy link
Owner

@fhiyo fhiyo commented Jul 18, 2024

total_weight += weight
return days_with_capacity + 1 <= days

return bisect_left(range(sum(weights) + 1), True, key=can_be_shipped)
Copy link

Choose a reason for hiding this comment

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

おお、range がランダムアクセスできて、空間計算量が O(1) なの知りませんでした。よく考えるとそりゃそうですね。
せっかくなので、lo=max(weights) を与えておくと探索範囲も同じになりますね。

こういう無駄なことしてました。
https://discord.com/channels/1084280443945353267/1233295449985650688/1246144715653513318

Copy link

@hayashi-ay hayashi-ay left a comment

Choose a reason for hiding this comment

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

良いと思います。


def can_be_shipped(capacity: int) -> bool:
total_weight = 0
days_with_capacity = 0

Choose a reason for hiding this comment

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

この変数名がちょっと分からなかったです。

Copy link

Choose a reason for hiding this comment

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

Can be shipped in N days with this capacity という気分でしょうが、days required か単に days かそのあたりじゃないかと思いますね。

Copy link
Owner Author

Choose a reason for hiding this comment

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

Can be shipped in N days with this capacity という気分でしょうが

そんな感じでした。たしかにdays_requiredの方が良いですね

total_weight += weight
return days_with_capacity + 1 <= days

low = 0
Copy link

Choose a reason for hiding this comment

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

1st のように low = max(weights) とすると

if weight > capacity:
    return False

が省略でき、コードが少しシンプルになると思います。

@SuperHotDogCat
Copy link

良いと思います

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

Successfully merging this pull request may close these issues.

5 participants