fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4.  
  5. const int MAX = 1e18;
  6.  
  7. signed main(){
  8. int n;
  9. cin>>n;
  10. int m = 1;
  11. int arr[n+10];
  12. bool ohno = false;
  13. for(int i=0; i<n; i++){
  14. cin>>arr[i];
  15. }
  16. sort(arr,arr+n);
  17. if(arr[0] == 0 ){
  18. cout << 0 << endl;
  19. return 0;
  20. }
  21. for(int i=0; i<n; i++){
  22. if(m > MAX/arr[i]){
  23. ohno = true;
  24. break;
  25. }
  26. m *= arr[i];
  27. }
  28. if(ohno){
  29. cout<< -1 <<endl;
  30. }else{
  31. cout << m <<endl;
  32. }
  33. }
  34.  
Success #stdin #stdout 0.01s 5288KB
stdin
3
101 9901 999999000001
stdout
-1