Connection Status:
Competition Arena > EmoticonsDiv1
SRM 612 · 2013-12-22 · by ltaravilse · Dynamic Programming
Class Name: EmoticonsDiv1
Return Type: int
Method Name: printSmiles
Arg Types: (int)
Problem Statement

Problem Statement

You are very happy because you advanced to the next round of a very important programming contest. You want your best friend to know how happy you are. Therefore, you are going to send him a lot of smile emoticons. You are given an int smiles: the exact number of emoticons you want to send.

You have already typed one emoticon into the chat. Then, you realized that typing is slow. Instead, you will produce the remaining emoticons using copy, paste, and possibly some deleting.

You can only do three different operations:
  1. Copy all the emoticons you currently have into the clipboard.
  2. Paste all emoticons from the clipboard.
  3. Delete one emoticon from the message.
Each operation takes precisely one second. Copying replaces the old content of the clipboard. Pasting does not empty the clipboard. You are not allowed to copy just a part of the emoticons you already have. You are not allowed to delete an emoticon from the clipboard.

Return the smallest number of seconds in which you can turn the one initial emoticon into smiles emoticons.

Constraints

  • smiles will be between 2 and 1000, inclusive.
Examples
0)
2
Returns: 2

First use copy, then use paste. The first operation copies one emoticon into the clipboard, the second operation pastes it into the message, so now you have two emoticons and you are done.

1)
4
Returns: 4

One optimal solution is to copy the initial emoticon and then to paste it three times. Another optimal solution is to copy the one emoticon, paste it, copy the two emoticons you currently have, and paste two more.

2)
6
Returns: 5

Copy. This puts one emoticon into the clipboard. Paste. You now have 2 emoticons in the message. Copy. The clipboard now contains 2 emoticons. Paste. You now have 4 emoticons in the message. Paste. You now have 6 emoticons in the message and you are done.

3)
18
Returns: 8
4)
11
Returns: 8

Sometimes we actually do delete an emoticon in the optimal solution.

Submissions are judged against all 66 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class EmoticonsDiv1 with a public method int printSmiles(int smiles) · 66 test cases · 2 s / 256 MB per case

Submitting as anonymous