CF1136B.Nastya Is Playing Computer Games

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Finished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters live, as quickly as possible.

There are nn manholes in the room which are situated on one line, but, unfortunately, all the manholes are closed, and there is one stone on every manhole. There is exactly one coin under every manhole, and to win the game Nastya should pick all the coins. Initially Nastya stands near the kk-th manhole from the left. She is thinking what to do.

In one turn, Nastya can do one of the following:

  • if there is at least one stone on the manhole Nastya stands near, throw exactly one stone from it onto any other manhole (yes, Nastya is strong).
  • go to a neighboring manhole;
  • if there are no stones on the manhole Nastya stays near, she can open it and pick the coin from it. After it she must close the manhole immediately (it doesn't require additional moves).

The figure shows the intermediate state of the game. At the current position Nastya can throw the stone to any other manhole or move left or right to the neighboring manholes. If she were near the leftmost manhole, she could open it (since there are no stones on it).

Nastya can leave the room when she picks all the coins. Monsters are everywhere, so you need to compute the minimum number of moves Nastya has to make to pick all the coins.

Note one time more that Nastya can open a manhole only when there are no stones onto it.

完成作业后,娜斯佳决定玩电脑游戏。她逐关通关,最终遇到了一个难题:她需要尽快离开一间住着大量怪物的房间。

房间里有 nn 个井盖,它们排成一条直线;但不幸的是,所有井盖都处于关闭状态,且每个井盖上恰好有一块石头。每个井盖下方恰好有一枚硬币;为了赢得游戏,娜斯佳必须拾取全部硬币。初始时,娜斯佳站在从左往右数第 kk 个井盖旁。她正在思考接下来该怎么做。

在每一轮操作中,娜斯佳可以执行以下三种动作之一:

  • 若娜斯佳当前所在的井盖上至少有一块石头,则她可将其中恰好一块石头扔到任意其他一个井盖上(是的,娜斯佳力气很大);
  • 移动至相邻的井盖(左或右);
  • 若娜斯佳当前所在的井盖上没有石头,则她可打开该井盖并拾取其下的硬币;拾取后她必须立即关闭井盖(此过程不消耗额外操作次数)。


图中展示了游戏的某一中间状态。此时娜斯佳可将石头扔向任意其他井盖,或向左/向右移动至相邻井盖。若她位于最左侧井盖旁(该井盖上无石头),则她可打开该井盖。

当娜斯佳拾取了所有硬币后,即可离开房间。由于怪物遍布各处,你需要计算娜斯佳拾取全部硬币所需的最少操作次数。

请注意:娜斯佳仅当所在井盖上没有石头时,才可打开该井盖。

输入格式

The first and only line contains two integers nn and kk, separated by space (2≤n≤50002 \leq n \leq 5000, 1≤k≤n1 \leq k \leq n) — the number of manholes and the index of manhole from the left, near which Nastya stays initially. Initially there is exactly one stone near each of the nn manholes.

第一行且唯一一行包含两个整数 nn 和 kk,以空格分隔(2≤n≤50002 \leq n \leq 5000,1≤k≤n1 \leq k \leq n)——分别表示井盖的数量,以及娜斯佳最初所处的井盖(从左往右数第 kk 个)。初始时,每个井盖旁恰好有一颗石子。

输出格式

Print a single integer — minimum number of moves which lead Nastya to pick all the coins.

输出一个整数——娜斯佳拾取所有硬币所需的最少移动次数。

输入输出样例

  • 输入#1

    2 2

    输出#1

    6
  • 输入#2

    4 2

    输出#2

    13
  • 输入#3

    5 1

    输出#3

    15

说明/提示

Let's consider the example where n=2n = 2, k=2k = 2. Nastya should play as follows:

  • At first she throws the stone from the second manhole to the first. Now there are two stones on the first manhole.
  • Then she opens the second manhole and pick the coin from it.
  • Then she goes to the first manhole, throws two stones by two moves to the second manhole and then opens the manhole and picks the coin from it.

So, 66 moves are required to win.

我们考虑 n=2n = 2、k=2k = 2 的示例。娜斯佳应按如下方式操作:

  • 首先,她将石子从第二个井盖扔到第一个井盖。此时第一个井盖上有两颗石子。
  • 接着,她打开第二个井盖,并从中拾取硬币。
  • 然后,她前往第一个井盖,分两次(每次扔一颗)将两颗石子扔到第二个井盖,再打开该井盖并从中拾取硬币。

因此,获胜共需 66 步。

输入解题思路,AI测评打分。不知道怎么写?

首页