Important Contest Instructions!!: Codewars System 2.0
Important Contest Instructions!!: Codewars System 2.0
Please read the following instructions carefully. They contain important information on how to write and submit
your solutions to the judges. If you have any question regarding these instructions, please ask a volunteer before
the contest starts.
Python 2.7.16
Python 3.7.4
GCC/G++ 9.1.0
Java OpenJDK 1.8.0_222
If you choose Java as the computer language to write your program, please make sure you name your Java
class as “codewars”. Here is an example,
You are strongly encouraged to submit Problem #0 (on the next page) prior to the start of the
competition to ensure fully understanding how to use the CodeWars System 2.0.
You can see Problem #0 (Points to Give Away, 50 points) is the first problem in the problem list on
the CodeWars 2.0 system.
Preface Problem 0
Hello World
The main purpose of this problem is submitting a testing program to 50 Points
ensure that the results are correctly executed on Sapporo system. It is
strongly recommended that each team submit the answer first.
Input
[none]
Output
Hello World
Preface Problem 1
There is a gym in Ninja Village where ninjas can build their bodies. Checking VIP
The gym has a special way of identifying VIP members. of the Gym
10 points
Every ninja will have a four-digit membership number (0001-9999)
after joining the gym. When the number is a prime number and after
the digits of the number are reversed, if it's still a prime number, the
number is a VIP number. For example, the membership number 1259
is a prime number and it is 9521 after being reversed, which is also a
prime number, so 1259 is a VIP number. The membership number
0011 is a prime number but it is 1100 after being reversed, which is not
a prime number, so 0011 is not a VIP number. Please use this identification method to help the Ninja
Gym design a VIP membership confirmation system.
Determine whether a four-digit input is a VIP number. The four-digit number ranges from 0001 to
9999. If it's a VIP number, output "IS VIP". If it's not a VIP number, output "NOT VIP".
Input
Example 1:
1234
Output
Example 1:
NOT VIP
Preface Problem 2
Ninjas from Ninjas College are going to have a mission, and they're Mission
all holding a scroll with numbers from 0 to 9. The dean arranged 15 points
them in two rows, with a maximum of ten people in each row, and
then added up the numbers with the person in the same position in
the other row.
If the sum exceeds nine, then the tens digit must be passed to the
next group of ninjas.
The final sum of numbers is the action code for this mission.
The input is two one-dimensional arrays, separated by a blank between the two arrays. Each element in
the array ranges from 0 to 9 and doesn't have blank. The output is a one-dimensional array and each
comma comes a blank behind.
It is guaranteed that the beginning of these two arrays will not be 0 unless the number itself is 0.
Input
Example 1:
[2,4,3] [6,8,1]
Output
Example 1:
[8,2,5]
Preface Problem 3
Flying Squirrel
After the ninja learned the ninjutsu "flying squirrel", the teacher
20 points
assigned him a mission. There is a mysterious archipelago in the
ocean outside the village. Besides flying over the archipelago using
the ninjutsu, please help calculate how many islands are in the
archipelago.
The map of the mysterious archipelago is 5x5 and is composed of 1
(land) and 0 (ocean). If there is vertical or horizontal connected land,
it's regarded as the same island.
In the input example, since all the land is connected together, there is only one island. Another
example, a map of the archipelago looks like:
10001
00100
00000
10001
00000
All the land is isolated by the ocean. We consider the land as 5 islands. Please help the ninja complete
this mysterious mission!
Input a 5x5 two-dimensional map of the archipelago, with 1 representing land and 0 representing
ocean. Output the number of islands.
Input
Example 1:
11110
11010
11010
00010
00000
Output
Example 1:
1
Preface Problem 4
Robot Dispatcher
Everyone in Ninja Village is required to wear a mask when going
25 points
out. If you don’t have a mask, the village head will find a way to
give it to you. To reduce the face-to-face communication between
people, they decide to utilize autonomous robots to deliver masks
in Ninja Village. The autonomous robot can only receive an array of
non-negative integers, where each element represents the
maximum number of steps it can advance from this position. It's
also required to walk from the initial position (the first element of
the array) to the last position (the last element of the array). Please help the village head design a
system to verify the array.
The input is a one-dimensional array. Each element of the array is the maximum number of steps it can
advance from this position, and separated by space.
Output True if the robot can walk from the start of the array to the end of the array.
Output False if the robot cannot walk from the start of the array to the end of the array.
Input
Example 1:
[2 4 3 0 2]
Output
Example 1:
True
Preface Problem 5
After Ninja woke up from a coma, he found himself in a small room Escape From
similar to an underground cell. The only exit is a blocked opening in the Dark Cell
the ceiling. Ninja also found a huge safe dial on the floor with 30 points
numbers 1 to 100.
The ninja tried to spin the dial so that 50 came under the opening
mark, but suddenly the room was filled with large amount of water,
almost choking the ninja to death. The ninja tried to spin the dial
again so that 75 came under the opening mark. The room continued
to be filled with water. The ninja spun the dial again so that 80 came
under the opening mark. But it was not water this time: the poison gas began to flow into the room.
The ninja tried his best to spin the dial so that 76 came under the opening mark. The exit in the ceiling
suddenly opened with a bang. He struggled to touch the slippery wall and climbed to the exit, finally
escaping from this terrible cell.
He later recalled that if the number he spun under the opening mark was smaller than 76, the room
would be filled with water; if the number he spun under the opening mark was larger than 76,
disgusting poison gas would flow into the room.
In the above description, before the exit in the ceiling was opened, the sum of the numbers that the
ninja spun was 50+75+80=205.
Given a safe dial with N numbers from 1 to N (N<=1000), before the exit in the ceiling is opened, what
is the minimum "sum" of the numbers that the ninja spins each time, which can guarantee that he
guesses the correct number before his death?
Here's an example of a safe dial with only 3 numbers: 1, 2, 3. If the ninja spins the dial to 1 first but the
correct number is not 1, he then has to spin either to 2 or 3. The ninja will choose the smaller number
(2), since if he guesses wrong, the "sum" of the numbers that the ninja spins each time will still be less.
Hence, the sum when he first spins to 1 is 1+2=3. If the ninja spins the dial to 2 first but the correct
number is not 2, he then has to spin either to 1 or 3. Because the ninja can know the correct number is
greater or less then 2 from the appearance of the water and gas, it's guaranteed that the exit in the
ceiling will open. Hence, the sum when he first spins to 2 is 2. If the ninja spins the dial to 3 first but the
correct number is not 3, he then has to spin either to 1 or 2. The ninja will choose the smaller number
(1), since if he guesses wrong, the "sum" of the numbers that the ninja spins each time will still be less.
Hence, the sum when he first spins to 3 is 3+1=4. The sums above are 3, 2 and 4, respectively, and the
smallest is 2. Therefore, the minimum "sum" of the numbers that the ninja spins each time is 2, which
can guarantee that he guesses the correct number before his death.
Input
Example 1:
3
Output
Example 1:
2
Preface Problem 6
The ninja starts from home and needs to buy a mask and 75% alcohol Mask and Alcohol
(he can either buy the mask first or the alcohol first, in no specific 35 points
order) on the way to work. In order not to be late, please help the
ninja plan a trip with the shortest total time.
Taking the image as an example, the ninja starts from home H and wants to detect the enemies in City
I. On the way, he has to buy a mask at the pharmacy T and 75% alcohol at the tobacco and liquor
store A. The time that the ninja may take is:
5 minutes from A to I
7 minutes from B to T
9 minutes from H to A
42 minutes from H to B
2 minutes from I to T
7 minutes from T to I
The trip with the shortest total time is to start from H, and go to tobacco and liquor store A to buy 75%
alcohol, then go through City I to the pharmacy T to buy the mask, and finally return to City I. It'll take
23 (9 + 5 + 2 + 7) minutes totally.
The first line of the input is a number of 4 uppercase letters without repeating. Letters are separated by
spaces.
The first letter indicates the starting point, the second letter indicates the end point, and the third and
fourth letters indicate the locations that must be passed.
The second to n+1-th lines of the input describe the start and end of the path and the required time.
The first letter indicates the start of the path, "->" indicates the direction of the path, and the second
letter indicates the end of the path. ": " followed by the required time.
The first line of the output are the letters from the starting point, and all locations on the way, to the
end point. List them in order, separated by spaces.
The second line is the total time.
Input
Example 1:
HITA
A -> I: 5
B -> T: 7
H -> A: 9
H -> B: 42
I -> T: 2
T -> I: 7
Output
Example 1:
HAITI
23
Preface Problem 7
Information
There are many, many ninjas in Iga-ryu. Each ninja has an
Exchange Network
independent number according to their strength. We call the of Iga-Ryu
powerful ninjas "Jonin" and the most powerful one is No. 1, and No. 2 50 Points
is second only to the most powerful ninja. Suppose there are N ninjas
in Iga-ryu, the number of the weakest ninja is N.
Since the missions are very confidential, and ninjas do not know the
actions of each other, Iga-ryu’s Jonin have set a rule, that is, every
time there is a mission, the subordinate ninjas will be divided into several teams in a specific way. They
give different missions according to the number of ninjas to each team. When ninjas encounter other
ninjas during the missions, they will use a rule to determine whether they belong to their own team so
as to exchange the confidential information, and even to determine whether the opponent is a spy
from other ninja school. The rule is: the ninjas share their numbers, when the numbers of two ninjas
have a common factor greater than 1, we say that two ninjas are in the same team. The term "team"
here can be regarded as a "set" in mathematics, rather than a direct connection between two people.
In the following example, although there is no other common factor between 6 and 35, since 15 can be
associated with each other, all of them are considered in the same team.
So from the point of view of Jonin, when they need a mission for a four-person team, they can send
out four ninjas which are {6, 15, 35, 3}, and the information exchange relationship is as in Image 1.
We can see that the group has only one team, and the number of people in the largest team is 4. We
use 1,4 to represent.
When we need two two-person team missions, we can send 4 ninjas which are {50, 7, 63, 10}, and the
information exchange relationship is as in Image 2.
This is a mission group composed of two teams, the number of people in the largest team is 2, we use
2,2 to represent.
When dispatching ninjas which are {21, 12, 7, 3, 2, 6}, we can notice that there is only one team in total,
and the information exchange relationship is as in Image 3.
Can you write a program based on the above example to automatically determine how many teams
that a certain group of ninjas can be devided to, and how many people are there in the largest team?
Suppose the maximum number of the ninjas N is 100000, and the minimum number is 1. A team
contains 20,000 people at most and 1 person at least. We use an array A to represent the numbers of
ninjas, and the array will meet the following conditions:
1 <= A[i] <= 100000
1 <= length(A) <= 20000
Input several numbers separated by comma. Each number represents a ninja.
Output 2 numbers. The first number is the number of teams and the second number is the number of
people in the largest team. The numbers are separated by a comma.
Input
Example 1:
6,15,35,3
Output
Example 1:
1,4
Preface Problem 8
Student Ratio
The story happened on Friday, November 13, 2020. Early in the
65 points
morning, the principal of the Ninjutsu College, Okawa Heiji Uzumasa,
summoned the first-year students to the playground.
The story ends here. Please help Shinbei calculate the number of students in each group so that:
(1) The sum of the ratio is exactly 13.
(2) The sum of the three groups (H,P and E) of students is the smallest.
We will use the sum of these three groups of students to test your output. The sum will be hundreds of
digits (very large). Please separate the sum into numbers by every three digits from right to left.
For example:
If the sum is 12345078, the numbers will be: 012,345,078
(If the leftmost number has less than three digits, add 0)
If the input is 0, please output the first number counted from the right side, which is 078.
If the input is 1, please output the second number counted from the right side, which is 345.
If the input is 2, please output the third number counted from the right side, which is 012.
If the input is N, please output the (N+1)-th number counted from the right side, and so on.
Input
Example 1:
18
Output
Example 1:
214