How to include the Constraints

eg:
1 ≤ T ≤ 7

1 ≤ |S| ≤ 10^5

2 Likes

make the program such that it passes the constraints , for eg- if 1<=n<=10^18 int variables wont work, you would have to use long long int. I hope that solves yr query

3 Likes

If you are asking on how to include these constrains in your code, then let me tell you that constrains are more like tips here, they tell you how big values might be and so that you can adjust your data types to hold those values ( like you need to use long for large numbers and long long for even larger numbers like for example, for 1 ≤ T ≤ 10^13, you will need long long int, a simple int will not be enough ). You don’t need to check for those constrains in your code, the values will always be within the constrains.

Let us consider your case

1 ≤ T ≤ 7

It means that the value for T entered during your program run on codechef will be >= 1 and <= 7.

And

1 ≤ |S| ≤ 10^5

Probably means that the length of S will be >= 1 and <= 10^5.

Hope this is what you were asking for in your question. :slight_smile:

8 Likes

You do not need to include the constraints. Constraints are given to check the approximate Order of the algorithm that can pass the problem.

You do not need to explicitly check the constraints in your solution.

Hope it Helps!!!

Happy Coding

4 Likes

Please specify what you actually want us to help you with.

In Code we should not include constraints ? Like if 1<=C<=6 …we need not include it in the code ? By using if statement somewhere in code ?

if , we have a necessity to add constraints , how to add them to the code

1 Like

Hey @akashabenki007 and @noobcoder67

Constraints are given for your reference, like what the ranges of input is gonna be, so that if you are using a statically typed language like C++ or similar, you need to declare a variable of appropriate datatype (eg. int or long long) to store the solution. Also, they help you in deciding an optimal approach such that it doesn’t exceed the time limit!

Hope that helps!

1 Like

well subtasks suck. even after writing code that works on example input, my subtasks shows wa. first program it worked. fro second onwards it doesnt. idk what to do and this literally has caused me a headache. this is why codechef sucks. atleast show how our subtasks are failing (sobs in corner). and also its not like the code didnt work. its shows the required output.

3 Likes