PROBLEM LINK:
Practice
Contest
Author: Akshay Venkataramani
Tester: Timothy Jeyadoss
DIFFICULTY:
Cakewalk
PREREQUISITES:
Arrays
EXPLANATION:
Simply find the product of the array. NOTE: Use long long int for all calculations. Integer variables are 32 bit, and can only calculate values precisely upto 10^9. Post that, long long int needs to be used(64 bit) for all calculations.
The constraints were N<=10 and A[i]<=15, resulting in a maximum possible product of 15^10, which is greater than 10^12.
AUTHOR’S SOLUTION:
Author’s solution can be found here
the question at CodeChef is not accepting responses. I have submitted a similar code but it says time limit exceeded. For your code too it says time limit exceded
However, there is still scope for optimization in the code. Here’s what I think could be improved (Do correct me if you find something
)
- unsigned int can be used as the constraints say.
- only the product variable needs to be
unsigned long long int
rest can be int
or even better unsigned short int
. However, that doesn’t make much difference.
- The cin / cout can be improved by turning off sync with stdio.