Contest 1 - Hints to Problems [OFFICIAL]

can you please explain the logic of mul3 qstn

Can Some Please help me out
i am getting Runtime Error in Multiple of 3 - MULTHREE
My solution is :
https://www.codechef.com/viewsolution/34113626

@sidhant007 kindly reply as i am having the same doubt.

1 Like

Why i am getting run time error in carvans prob??

int main()
{

int t;
scanf("%d",&t);
while(t--)
{
    int n;
    scanf("%d",&n);
    int a;
    int min,l=1; //l will hold the number of cars with maximum speed
    scanf("%d",&min);
    for(int i = 1;i<n;i++)
    {
        scanf("%d",&a);
        if(a<min)
        {
            min=a;
            l++;
        }
        
    }
   printf("%d\n",l);

}
return 0;
}

what if sum>10

u have only done for number from [1,10];
what if d0+d1>10,if d0=7 and d1=9

I figured that there was a pattern. But when I submit, it said it was wrong answer.

import sys
import math

def analyze_this(a_list):
if a_list[1]%2==0:
count=int(a_list[1]/2)
else:
if a_list[0]==a_list[2]:
count=math.floor(a_list[1]/2)
else:
count=math.ceil(a_list[1]/2)
return count

T = int(sys.stdin.readline().strip())

if T>0 and T<=10:
x=0
while x<T:
G=int(sys.stdin.readline().strip())
if G>0 and G<=20000:
y=0
while y<G:
arr=list(map(int,sys.stdin.readline().strip().split(ā€™ ')))
if (arr[0]>0 and arr[0]<=2) and (arr[2]>0 and arr[2]<=2) and (arr[1]>0 and arr[1]<=109):
print(analyze_this(arr))
y+=1
x+=1

Can someone please tell me most effective way for finding factorial of number ā€¦since in problem FCTRL , I am unable to find factorial of such large nā€¦Help Please.

Donā€™t find factorial of number, instead just count the number of zeroes
checkout this article : Count trailing zeroes in factorial of a number - GeeksforGeeks

1 Like

hello admin plz help me with the problem coinflip in dsa learming series contest 1
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
long long int t;
cin >> t;
while (tā€“)
{
long long int G;
cin >> G;
while (Gā€“)
{
long long int i, j, count = 0, n, q;
cin >> i >> n >> q;
long long int c[n];
for (j = 1; j <= n; j++)
{
c[j] = i;
}
//n coins or n rounds
//value of coins (j)
//state of coins c[j]
for (j = 1; j <= n; j++)
{
if (c[j] % 2 == 0)
{
if ((n - j + 1) % 2 == 0)
{
c[j] = 2;
}
else
{
c[j] = 1;
}
}
else
{
if ((n - j + 1) % 2 == 0)
{
c[j] = 1;
}
else
{
c[j] = 2;
}
}
}
for (j = 1; j <= n; j++)
{
//after all operations
if (c[j] == q)
{
count++;
}
else
{
continue;
}
}
cout << count << " " << endl;
}
}
return 0;
}
my solution is giving TLE.

Can someone please explain to me the problem statement ZCO14003? Iā€™m not getting the question properly

Hi,
Can anyone please help me. What I am doing wrong in my solution (CARVANS)
https://www.codechef.com/viewsolution/35777684

In the third case, car I which is moving at the speed of 4 can go at itā€™s max speed, car II cannot go at itā€™s max speed, car III can move at itā€™s max speed of 1 and car IV and V canā€™t exceed speed 1.
Hence the ans is 2ā€¦car I and car III.

Ques : MULTHREE.
Whatā€™s wrong in this code ?

#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long t;
    cin >> t;
    while(t--){
        long long k,sum,d0,d1,cur,remaining;
        cin >> k >> d0 >> d1;
        sum = d0+d1;
        cur = (d0+d1)%10;
        remaining=k-2;
        while(remaining>0){
            sum+=cur;
            cur = (cur+cur)%10;
            remaining--;
            if(cur==0 || cur==2){
                break;
            }
        }
        sum += 20*(remaining/4);
        int a[4]={2,4,8,6};
        for(int i=0; i<remaining%4; i++){
            sum+=a[i];
        }
        if(k==2){
            sum = d0+d1;
        }
        if(sum%3==0){
            cout << "YES\n";
        }
        else{
            cout << "NO\n";
        }
    }
}

In this case, the pattern of speed will be 8 3 x where x<=3 so first two cars are at their max speed(8 ,3).

for the coin flip problem, can anybody give the exact output?
3
2
1 5 2
2 1001 1
3
1 22 2
1 99 1
2 669 1
4
1 10 1
1 11 2
2 12 1
2 13 2

Hereā€™s what I got for the above input :
3
501
11
49
335
5
6
6
6

Code : https://ideone.com/YDwTLL

Can anyone help spotting what is wrong here ? Running well and good but wrong answer when submitting :frowning_face: :frowning_face:: CodeChef: Practical coding for everyone

Consider the test input:

1                                                       
10
10 9 8 7 6 5 4 3 2 1
2 Likes

thaks i get it

1 Like