PlayingWithPlanks
TCO19 SRM 743 · 2018-12-08 · by boba5551
Problem Statement
You are given a plank of length plankLength. You want to cut the plank into exactly pieces pieces such that the length of each piece is a (positive) integer and all the lengths are distinct.
If it is possible to cut the plank in the described way, return "possible". Otherwise return "impossible".
Notes
- Note that the return value is case-sensitive.
Constraints
- plankLength will be between 1 and 1,000,000, inclusive.
- pieces will be between 1 and 1,000, inclusive.
9 3 Returns: "possible"
One possibility is to cut the plank into pieces of lengths 1, 3 and 5.
12 1 Returns: "possible"
9 4 Returns: "impossible"
It can be shown that there is no way to cut a plank of length 9 into 4 pieces of different integer lengths.
10 4 Returns: "possible"
750932 901 Returns: "possible"
Submissions are judged against all 31 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class PlayingWithPlanks with a public method string canItBeDone(int plankLength, int pieces) · 31 test cases · 2 s / 256 MB per case