Contest 1 - Hints to Problems [OFFICIAL]

@gulshan_yadav
while(n–)
because n inputs will be given.
You made it too complex ig.You can check my solution here(not very clear but understandable)

number_of_testcases
    {
        int n ; cin >> n ;
        int ans = 0 ;
        string a ; cin >> a ;
        while(n--){
            string b ; cin >> b ;
            if(b == "CONTEST_WON"){
                ans += 300 ;
                int rank ; cin >> rank;
                if(rank <= 20)
                ans +=20-rank;
                
            }
            else if(b == "TOP_CONTRIBUTOR"){
                ans+=300;
            }
            else if(b == "BUG_FOUND"){
                int severity ; cin >> severity ;
                ans+=severity;
            }
            else if(b == "CONTEST_HOSTED"){
                ans+=50;
            }
        }
        (a == "INDIAN") ? (cout << ans/200) : (cout << ans/400) ;
        cout << "\n";
    }
2 Likes

This is my solution to coin flip and its shows TLE as complexity is O(n2). Is there any other way to optimise it?

#include <iostream>
using namespace std;

#define datatype long long int

int main()
{
    datatype testcases;
    cin>>testcases;
    while(testcases--)
    {
        datatype games;
        cin>>games;
        while(games--)
        {
            datatype initialState, numberOfRounds, prediction;
            cin>>initialState>>numberOfRounds>>prediction;
            datatype arr[numberOfRounds];

            if(initialState == 1) // head
                for(datatype i=0; i<numberOfRounds; i++)
                    arr[i]=1;
            else // tail
                for(datatype i=0; i<numberOfRounds; i++)
                    arr[i]=-1;

            for(datatype i=0; i<numberOfRounds; i++)
            {
                for(datatype j=0; j<i; j++)
                    arr[j]= -arr[j];
            }

            datatype count=0;

            for(datatype i=0; i<numberOfRounds; i++)
            {
                if(prediction == 1)
                {
                    if(arr[i] == -1)
                        count++;
                }
                else
                {
                    if(arr[i] == 1)
                        count++;
                }
            }
            cout<<count<<endl;
        }
    }
    return 0;
}
1 Like

thanks you :slight_smile: lost_boy12
i was taking string and rank both in one string only so that’s why its too complex. :slight_smile:

3 Likes

for ZCO14003 iam getting AC for subtask 10,11,12 and 21 remaining are WA .I didn’t understand this.

1 Like

3
1
10
3
8 3 6
5
4 5 1 2 3
So for the 3rd test case answer should be 3 but here it is given 2 in output.
Can u please explain it??

1 Like

Why is that? Since 8 3 6 are in the order they entered lane. 8 can be at its max speed so does the 3. Only 6 cannot go to its peak speed as 3 is in front of it.

2 Likes

try long long data type.

1 Like

Can you explain?

1 Like

5 cannot be speeder than 4 and in the same way 2 & 3 cannot be speeder 1. So only 4 and 1 are at there max speed.

1 Like

consider all as bars of given size and every bar must be the smallest of all the bars in it’s left.

1 Like
                  BigInteger k = sc.nextBigInteger();
	      long d0 = sc.nextLong();
	      long d1 = sc.nextLong();
	      long sumofdigi = d1+d0;
	      long sum = d1+d0;
	      for(int i=2;i<k.intValue();i++){
	          long digi = sum%10;
	          sumofdigi+=digi;
	          sum+=digi;
	      }
	      
	      if(sumofdigi%3==0)
	       System.out.println("YES");
	      else
	       System.out.println("NO"); 

it is showing TLE error but the complexity is O(n). Can anyone help?

1 Like

why i m getting wrong answer in LAPIN.i m getting right answer in my compiler for different test cases. plz explain

1 Like

Why is this approach incorrect?

1 Like

check constraints o(n) will not work

1 Like

For laddu problem, iterate for number of activities and everytime check the input. It should be one among 4 i.e, CONTEST_WON, TOP_CONTRIBUTOR, BUG_FOUND, CONTEST_HOSTED for a specific activity update the global variable using the given formulae. after iterating number of activities. divide global variable by 200 or 400 based on origin and then print it.

2 Likes

tell more about your approach.

1 Like

yes @gulshan_yadav

1 Like

Because if you are taking the mod to each digits and then adding them, at the end you will have a number which is more than divider(i.e, 10 in the problem). so after that you will have to take the mod again.

2 Likes

Broad intuition is:

Lets say the number comes out to be 453, here 453 is divisible by 3, because (4 + 5 + 3) mod 3 = 0, but ((4 + 5 + 3) mod 10) mod 3 = (12 mod 10) mod 3 = 2 mod 3 = 2, so if you get the modulo of everything under 10, then it doesnt work, mainly because of the following statement:
((a mod 10 + b mod 10) mod 3) != (((a + b) mod 10) mod 3), for all a, b in [0, 9] * [0, 9]

2 Likes

int main() {
// your code goes here
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n,fixprice=0;
cin >>n;
long long a[n];
unsigned long long sum[n]={0};
long long count[n]={0};
for(int i=0;i<n;i++)
{
cin >>a[i];
}
int size1=sizeof a/sizeof a[0];
sort(a, a+size1);
for(int j=0;j<n;j++)
{ fixprice=a[j];
count[j]=(n-j);
sum[j]=count[j]*fixprice;
}

int size=sizeof sum/sizeof sum[0];
 sort(sum, sum+size, greater<int>()); 
 cout << sum[0] <<"\n";

return 0;

}

This is the code