TALAZY - editorial

PROBLEM LINK:

Practice
Contest

Author: Tuấn Anh Trần Đặng
Tester: Kamil Dębowski
Editorialist: Tuấn Anh Trần Đặng

DIFFICULTY:

Cakewalk

PREREQUISITES:

Ad-hoc

Solution

In this problem we just need to “simulate” the activities of the Lazy Jem.

    res = 0;
    while (n) {
        int problems = (n + 1) / 2;
        res += problems * m;
        n -= problems;
        if (n) {
        res += b;
        }
        m = m * 2;
    }

Author’s/Tester’s Solutions:

Setter’s solution
Tester’s solution

The problem is not visible in Practice section. Please fix @admin @tuananh93

1 Like

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
int main()
{
int t;
cin>>t;
while(t–)
{
long long n,b,m;
cin>>n>>b>>m;
long long ans=0;
while(n>0)
{
if(n%2)
{
ans+=((n+1)/2)*m;
n-=(n+1)/2;
if(n>0)
ans+=b;
//cout<<“Ans=”<<ans<<" ";
}
else
{
ans+=(n/2)m;
n-=(n/2);
if(n>0)
ans+=b;
//cout<<“ans=”<<ans<<" ";
}
m
=2;
}
cout<<endl;
cout<<ans<<endl;
}
return 0;
}

Why is it giving the wrong answer? Plz, someone help…
https://www.codechef.com/viewsolution/42908863
#include<bits/stdc++.h>
#include <stdio.h>
#include
#include <string.h>
using namespace std;
#define lli long long int
#define tc lli tc;scanf(“%lld”,&tc);while(tc–)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORN(i, a, b) for (int i = (a); i < (b); i++)

int main()

{
tc{
lli n,b,m,counter=0,t=0,i=0;
scanf(“%lld %lld %lld”,&n,&b,&m);
while(n>0){
if(n%2==0){t=n/2; n=n-(n/2);}
else{t=(n+1)/2; n=n-((n+1)/2);}
counter+=(tmpow(2,i));
i++;
if(n>0){counter+=b;}
}
cout<<counter<<endl;
}
}

This is an easy problem to try out your recursion technique. If there’s only one problem left, solve in the given time, otherwise add up the time to the next break and call the solver again with the new situation.

10^8 maximum means that the recursion depth will be less than 1+ \log_2 10^8 < 30.

Python solution with recursion