Cook Off Discuss (COOK114)

Opening a discussion here for the latest Cook off XD
From Div 2:
I solved first two questions and can somebody explain me rest three questions.
A solution was create an array of size 1e5 and fill it up with multiples of the elements of A array, then find the largest gap between them.
B solution was counting the number of factors of abs(a-b). (which were the roll numbers of the two kids).
I am sorry if i am unable to provide proofs for the solution but i will elaborate them a bit later :slight_smile:

3 Likes

The largest gap will be equal to the minimum of the numbers in the list.

4 Likes


anyone done this with logic!

which question are you talking about?

solution of A : min element in the given array.

2 Likes

p

Put the logic aside.You haven’t checked any of the constraints.U straight away declared everything as int and fixed the array sizes to be 100.

what is logic for [Range AND] ? i did like finding nearest 2 power element of L and doing ans with loop continution until that nearest number. but i am getting TLE can anyone explain

see, what i have thought the logic,
we have something common from 2-3,4-7,8-15,16-31…
can you find any order,
yes, 2^n to 2^n-1,
so next is, if we are given Left =5, and right =10,
then we will find our range of Left, it comes under 4-7.
now, the above of 7 will all be zero(5^6^7^8=0 as they don’t have common bit same),
we gave name near=4, and next=7. now,
we will check if right<=next, if yes, then (right-left)*near+left;
else, (right-next)*near+left;
this is my logic. but i am getting wrong answer. but it should be correct.

chef chick

#include<iostream>
using namespace std;
int main(){
    int t,i,j;
    cin>>t;
    long long int min[t];
    int n[t];
    for(i=0;i<t;i++){
        cin>>n[i];
        long long int a[t][i];
        for(j=0;j<n[i];j++){
            cin>>a[i][j];
        }
        if (n[i]==1)
            cout<<a[i][0];
        min[i]=a[i][0];
        for(j=1;j<n[i];j++){
            if (a[i][j]<a[i][j-1])
                min[i]=a[i][j];
        }
        cout<<min[i]<<endl;
    }
    return 0;
}

please format your code :slight_smile:

what .

go and edit your code,
Ctrl+A
Ctrl+shift+C
then reply.

#include<iostream>
using namespace std;
int main(){
    int t,i,j;
    cin>>t;
    long long int min[t];
    int n[t];
    for(i=0;i<t;i++){
        cin>>n[i];
        long long int a[t][i];
        for(j=0;j<n[i];j++){
            cin>>a[i][j];
        }
        if (n[i]==1)
            cout<<a[i][0];
        min[i]=a[i][0];
        for(j=1;j<n[i];j++){
            if (a[i][j]<a[i][j-1])
                min[i]=a[i][j];
        }
        cout<<min[i]<<endl;
    }
    return 0;
}
1 Like

Status Wrong Answer

you have to run code for t test cases…

runtime error

#include<iostream>
using namespace std;
int main(){
    int t,i,j;
    cin>>t;
    long long int min[t];
    int n[t];
    for(i=0;i<t;i++){
        cin>>n[i];
    }
    long long int a[t][102];
    for(i=0;i<t;i++){
        for(j=0;j<n[i];j++){
            cin>>a[i][j];
        }
    }
    for(i=0;i<t;i++){
        if (n[i]==1)
            cout<<a[i][0];
        min[i]=a[i][0];
        for(j=1;j<n[i];j++){
            if (a[i][j]<a[i][j-1])
                min[i]=a[i][j];
        }
        cout<<min[i]<<endl;
    }
    return 0;
}

https://www.codechef.com/viewsolution/29083196
Hello!
Check out this solution

    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n],ans=INF;
        for(int i=0,i<n;i++) cin>>a[i],ans=min(a[i],ans);
        cout<<ans<<'\n';
    }