QOJ.ac

QOJ

実行時間制限: 12 s メモリ制限: 256 MB 満点: 100

#10623. 货车

統計

在一条一维轨道上停放着 $n$ 节车厢。最初,没有任何两节车厢是连接在一起的。在每一步操作中,你可以将两组相邻的已连接车厢合并,前提是这两组车厢的数量之差不超过 $d$。执行此类合并所需的时间取决于被合并组中车厢的数量。你的任务是将所有车厢合并成一个包含 $n$ 节车厢的列车。

将一组包含 $w$ 节车厢的组与一组包含 $v$ 节车厢的组进行合并(前提是 $|w - v| \le d$)的代价由函数 $(aw + bv) \pmod{1001}$ 给出。

输入格式

输入仅一行,包含四个正整数 $n, d, a$ 和 $b$ ($1 \le n \le 10^{16}, 1 \le d, a, b \le 1000$)。

输出格式

输出仅一行,包含一个整数,表示将所有 $n$ 节车厢合并成一列火车的最小代价。

样例

输入格式 1

5 1 1 1

输出格式 1

12

说明

将第一节车厢与第二节合并(代价 2),第三节与第四节合并(代价 2),然后与第五节合并(代价 3),最后将两组已形成的组进行合并(代价 5)。

测试用例

1ocen: $n = 10, d = 3, a = 2, b = 3$ 2ocen: $n = 10^5, d = 1000, a = 3, b = 5$ 3ocen: $n = 10^{16}, d = 300, a = 3, b = 5$

评分

Podzadanie Ograniczenia Punkty
1 $n \le 100\,000$ 21
2 $d \le 300$ 46
3 无额外限制 33

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.