Skip to content

Conversation

@docto-rin
Copy link
Owner

- 関数名key_functionは中身に比して素朴すぎするので、可読性のために改善すべき。is_feasibleとか。
- key_functionの計算量が悪い。weightで一重ループを回して貪欲的に区切れる。
- 手作業でやってた時は明らかにこう考えていたのに、二分探索に囚われすぎてなぜか無理やりdayごとに二分探索する羽目になった。
- 時間計算量: O(logC * days * log n) -> O(logC * n)に改善できる。

Choose a reason for hiding this comment

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

上のやり方は自分は考え付かなかったので勉強になりました。
コードとしては実装2のほうが分かりやすく感じますが、daysがnに比べて小さい場合は上のほうが計算量が少なくなる優位性はあるのかなと考えました。

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。

確かにそうですね。船が大きく一気に運ぶ前提ならアリかもしれません。

Comment on lines +142 to +144
if passed_days == days:
return False
loaded = weight

Choose a reason for hiding this comment

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

passed_days += 1した直後にチェックしたいという意図も分かるのですが、個人的にはloaded = weightの代入を先に書いた方が少し見やすいかなと思いました。
またパフォーマンスが問題でないのなら、このifを省いてreturnのタイミングでpassed_days < daysを判定するのもいいかなと思いました。

Copy link
Owner Author

@docto-rin docto-rin Oct 20, 2025

Choose a reason for hiding this comment

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

ありがとうございます。

passed_days += 1した直後にチェックしたいという意図も分かるのですが、個人的にはloaded = weightの代入を先に書いた方が少し見やすいかなと思いました。

まさに、そこで悩みました。一応時系列を意識して書いてみました。今思いつきましたが、こういうのもいいかも知れません。

if passed_days + 1 == days:
    return False
passed_dayes += 1
loaded = weight

またパフォーマンスが問題でないのなら、このifを省いてreturnのタイミングでpassed_days < daysを判定するのもいいかなと思いました。

これに関してはシンプルさとパフォーマンス最適化のトレードオフですが、個人的にはこの程度ならearly returnする価値が勝ると思いました。

- Step 2で色々と参照されていて、追随側としてはありがたい。
- [実装2](#実装2)の異常入力に対する耐性
- weightが0や負の値であっても、例外は送出しない。
- 負の値とかは例えば船から荷物を取り出す操作とかに対応させられそう。(ノーショー)

Choose a reason for hiding this comment

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

なるほど、この考え方は思いつきませんでした!

## Step 2

- レビュー by GPT-5
- 関数名key_functionは中身に比して素朴すぎするので、可読性のために改善すべき。is_feasibleとか。
Copy link

Choose a reason for hiding this comment

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

is_shippable はいかがでしょうか?

Copy link
Owner Author

@docto-rin docto-rin Oct 20, 2025

Choose a reason for hiding this comment

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

ありがとうございます。

shippableも少し検討したんですが、"able"が複数日にわたる輸送計画の可能性ではなく、もっと狭い「まだ船に積むことができるか ある1日において輸送可能かどうか」のニュアンスを持つ気がして、少し違う気がしたのでふんわりとfeasibleにしてみました。

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.

4 participants