Conversation
| if (currentSumWeights + weight <= capacity) { | ||
| currentSumWeights += weight; | ||
| } else { | ||
| currentSumWeights = weight; | ||
| currentDays++; | ||
| if (days < currentDays) { | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
個人的にはここのif-elseはif-continueで書きたいと感じました。
| if (currentSumWeights + weight <= capacity) { | |
| currentSumWeights += weight; | |
| } else { | |
| currentSumWeights = weight; | |
| currentDays++; | |
| if (days < currentDays) { | |
| break; | |
| } | |
| } | |
| if (currentSumWeights + weight <= capacity) { | |
| currentSumWeights += weight; | |
| continue; | |
| } | |
| currentSumWeights = weight; | |
| currentDays++; | |
| if (days < currentDays) { | |
| break; | |
| } |
There was a problem hiding this comment.
ありがとうございます。たしかにネストへるしいいですね
| // O(log(m) * n), m: 最大値*n, n: weightsの要素数 | ||
| // m = 500n = 500 * 5 * 10 ^ 4 = 25 * 10 ^ 6 → 2 * 10 ^ 7 | ||
| // nlog(m) = 500 * log(2 * 10 ^ 7) = 500 * 7 * log(20) = 3500 * log (20) = 3500 * (2log(2) + log(5)) = 3500 * (2 + 2.3) = 3500 * 5 = 175000 = 2 * 10 ^ 5 | ||
| // 大体Javaが1sで10^7くらい処理ができるとすると、2 * 10 ^ 5 / 10 ^ 7 = 2 / 10 ^ 2 = 20msくらいで完了しそう |
There was a problem hiding this comment.
自分はJavaにそこまで詳しくないですが、1sで10^7くらい、はやや過小評価に感じました。
JITコンパイラ特有のスロースタート的な特性などもあると思いますが、このくらいの繰り返しが明確で単調、インスタンス生成も特にない処理なら、JIT最適化後は効率的に機械語に翻訳され1sに10^8-10^9くらい行くかなと思いました。(CPUのクロック周波数が数GHz程度という前提のもと)
There was a problem hiding this comment.
ベンチマークサイトによると Java は C に比べて 3~4 倍程度遅いようです。
- https://github.com/niklas-heer/speed-comparison
- https://benchmarksgame-team.pages.debian.net/benchmarksgame/box-plot-summary-charts.html
1s に 107~108 くらいで見積もるとよいと思いました。
There was a problem hiding this comment.
私も 10^8-10^9 くらいで見積もりそうですが、しかし、一般にソフトウェアの速度は保守的に見積もったほうがいいんですよね。(予想外に速くて困ることはあまりないが逆は困ることがあるので。)
There was a problem hiding this comment.
ありがとうございます。そうですね、少し幅を 10^7~10^8 くらいで認識します。
| 走査部分について | ||
| 1, 不変条件 | ||
| 見つけたいもの:条件を満たす最小のcapacity | ||
| left: これを以下のCapacityでは条件をみたさない。 |
There was a problem hiding this comment.
これ未満のCapacityでは条件をみたさない。ですね
問題:https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/description/