did you solve laddu problem?
if yes then please share the approach .
@gulshan_yadav
There is no specific approach for this problem ig . Brute force worked for me
can u post it here.
If anyone is having difficulty solving the problems of Code-Chef DSA Series-1 problems, you can refer to the this post: Code-Chef DSA Series-1 Editorial.
P.S. But before referring the above post make sure that you have tried everything for solving a problem.
@lost_boy12
#include
using namespace std;
#include<bits/stdc++.h>
void solve(){
int n;
cin>>n;
string ori;
getline(cin,ori);
string cont;
getline(cin,cont);
string contest=cont.substr(12);
int rank=stoi(contest);
string top;
getline(cin,top);
string bug;
getline(cin,bug);
string b=bug.substr(10);
int ra=stoi(b);
string host;
getline(cin,host);
int total=300+(20-rank)+300+ra+20;
cout<<total<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
@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";
}
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;
}
thanks you lost_boy12
i was taking string and rank both in one string only so that’s why its too complex.
for ZCO14003 iam getting AC for subtask 10,11,12 and 21 remaining are WA .I didn’t understand this.
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??
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.
try long long data type.
Can you explain?
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.
consider all as bars of given size and every bar must be the smallest of all the bars in it’s left.
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?
why i m getting wrong answer in LAPIN.i m getting right answer in my compiler for different test cases. plz explain
Why is this approach incorrect?