Skip to content

1011. Capacity To Ship Packages Within D Days#46

Open
ryoooooory wants to merge 1 commit intomainfrom
task/1011
Open

1011. Capacity To Ship Packages Within D Days#46
ryoooooory wants to merge 1 commit intomainfrom
task/1011

Conversation

@ryoooooory
Copy link
Copy Markdown
Owner

Comment on lines +37 to +45
if (currentSumWeights + weight <= capacity) {
currentSumWeights += weight;
} else {
currentSumWeights = weight;
currentDays++;
if (days < currentDays) {
break;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

個人的にはここのif-elseはif-continueで書きたいと感じました。

Suggested change
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;
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。たしかにネストへるしいいですね

// 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くらいで完了しそう
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

自分はJavaにそこまで詳しくないですが、1sで10^7くらい、はやや過小評価に感じました。

JITコンパイラ特有のスロースタート的な特性などもあると思いますが、このくらいの繰り返しが明確で単調、インスタンス生成も特にない処理なら、JIT最適化後は効率的に機械語に翻訳され1sに10^8-10^9くらい行くかなと思いました。(CPUのクロック周波数が数GHz程度という前提のもと)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ベンチマークサイトによると Java は C に比べて 3~4 倍程度遅いようです。

1s に 107~108 くらいで見積もるとよいと思いました。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

私も 10^8-10^9 くらいで見積もりそうですが、しかし、一般にソフトウェアの速度は保守的に見積もったほうがいいんですよね。(予想外に速くて困ることはあまりないが逆は困ることがあるので。)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。そうですね、少し幅を 10^7~10^8 くらいで認識します。

走査部分について
1, 不変条件
見つけたいもの:条件を満たす最小のcapacity
left: これを以下のCapacityでは条件をみたさない。
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

これ未満のCapacityでは条件をみたさない。ですね

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