Chief Thief

A group of thieves steal only money. Every morning they deposit the money to their leader. The leade…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

#include iostream
#include cstdlib
using namespace std;
int index;
int main()
{
long long n, *ara, *result;
long long sum=1;
cin>>n;
if(n==1) {
cin>>n;
cout<<n<<endl;
return 0;
}
ara = (long long *)malloc(sizeof(long long)*n);
result = (long long *)malloc(sizeof(long long)*n);
for(int i=0; i<n; i++) {
cin>>ara[i];
}
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
if(ara[i]==ara[j]) continue;
else sum=sum * ara[j];
}
result[index++] = sum;
sum=1;
}
for(int k=0; k<index; k++) {
if(k==0) cout<<result[k];
else cout<<" "<<result[k];
}
cout<<endl;
free(ara);
free(result);
return 0;
}

What’s the problem with this code?

I used 2 different codes, but both of the time, CLE error took place. Anyone to help?

def prod(list):
    p = 1
    for j in list:
        p *= j
    return p
n=int(input())
k=[]
m=list(map(int, input().split()))
for i in range(n):
    b=m[:i]+m[(i+1):]
    k.append(prod(b))
print(*k)

and,

n=int(input())
p=[]
m=list(map(int, input().split()))
for i in range(n):
    b=m[:i]+m[(i+1):]
    l=1
    for j in b:
        l*=j
    p.append(l)
print(*p)

@rased_299, I see that you were able to solve the problem. So, I am skipping your question.
@Rafeed, You are getting CLE because your code is not efficient. Try to figure out a more efficient approach to solve the problem.
And again, Both of your codes has the same logical approach. So, it does not count.

#include<bits/stdc++.h>
using namespace std;
int main()
{
   long int t;
    cin>>t;
    long int a[t];
    vector<int>s;
    for(int i=0;i<t;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<t;i++)
    {
       long int sum=1;
        for(int j=0;j<t;j++)
        {
            if(a[i]==a[j])
                sum=sum+0;
            else
                sum=sum*a[j];
        }
        cout<<sum;
        if(i<t-1)
            cout<<" ";
    }
    return 0;
}

Showing wrong answer for the 4th test case…whats wrong?

def mulpti():
temp5 = b * c * d
temp6 = a * c * d
temp7 = a * b * d
temp8 = a * b * c
def somthing():
if temp5 <= 2 ** 31 and temp6 <= 2 ** 31 and temp7 <= 2 ** 31 and temp8 <= 2 ** 31:
print(temp5, temp6, temp7, temp8)
somthing()

d = int(input())
a, b, c, d = map(int, input().split())
if a <= 105 and b <= 105 and c <= 105 and d <= 105:
mulpti()

showing # Test case 5 error
why?

input();l=list(map(int,input().split()));p=1
for j in l:p*=j
print(" ".join([str(p//i) for i in l]))

This code’s getting RE at testcase #3. Any suggestions?

Run time for python should be increased 2x.

2 Likes

@jahir.raihan Python 2 and 3.7 are 2x already. Though Python 3.8 is still at 1x.
@hjr265 bhaiya, please increase the limit.

1 Like

@anonyo.akand Thank you for reporting. Done!

1 Like

This was a tricky easy question I must say :rofl: