Editorials should be made simple

Can anybody suggest me some good set of problems and solutions of Graphs/trees along with DP ? Video links would be of great help. :confused:

Try this out

6 Likes

If you have the time, then I have one more query :sweat_smile:
I noticed that when you declared some variables outside the loop in my program the execution time decreased quite a bit, I have read about this before and almost every answer on stackoverflow states that itā€™s best to keep variables as close as possible to their scope and this does not affect the execution time. But in this case this doesnā€™t seems to hold. Of course if we are using same value in every iteration it would be best to declare it outside the loop. But in this case thatā€™s basically the same thing, we are calling memeset anyway.
Are there any cases where i shall actually prefer declaring them outside ? (to bypass a tight TLE)

I think allocation of memory in a loop is bad.
As it will have to redeclare it again and again in runtime.
Hence I took it outside.
I keep it outside.
I am not sure if keeping it in loop optimizes code.
One optimization is declare it as static
It reduces running time.

I read that modern compilers automatically prevents re-deceleration, but i guess that might not be true for all cases. Thanks Anyway!
Btw do you have any tip to optimize my code? complexity would be fine if i use a map
( N āˆšn , even though it takes more time :rofl: ) .

EDIT: finally AC, all i had to do was assign ct[]'s used places back to 0 while calculating the answer, this makes it q*āˆšn again. XD this was so simple yet took so much time :joy:.
Thanks for your help mate!

Glad that I could help !!

Yup that is what I do generally
:slight_smile:

XD
completing 20 chars

LolšŸ˜‚
Codeforces editorials are more confusing, they are not even editorials, they are just hints with no reading-friendly code. See comment section of that blog and you will come to.
Codechef editorials explain from scratchā€¦

What is that? Iā€™ve seen this earlier too.

@ darkcodernavv If youā€™re writing a comment, it must contain atleast 20 characters, thats the wired char limit discuss has.

1 Like

Mate i am talking about things like this .
Editorialisā€™t solution of proxy question .
//teja349
#include <bits/stdc++.h>
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill - cout << setfill (ā€˜xā€™) << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x) cout<<fixed<<val; // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;iā€“)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (100010001000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector
#define vll vector
#define viii vector
#define mod (100010001000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// find_by_order() // order_of_key
typedef tree<
int,
null_type,
less,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

int main(){
std::ios::sync_with_stdio(false); cin.tie(NULL);
int t;
cin>>t;
while(tā€“){
int d;
cin>>d;
string s;
cin>>s;
int i,cnt=0,gg=0;
int sz=s.length();
rep(i,sz){
if(s[i]==ā€˜Pā€™)
cnt++;
}
int j,val,good=0;
val=(75*sz+99)/100;
f(i,2,sz-2){
if(cnt>=val)
break;
if(s[i]==ā€˜Pā€™)
continue;
good=0;
f(j,-2,0){
if(s[i+j]==ā€˜Pā€™){

                good=1;
                break;
            }
        }
        if(good==0)
            continue;
        good=0;
        rep(j,3){
            if(s[i+j]=='P'){

                good=1;
                break;
            }
        }
       // cout<<i<<endl;
        if(good){
            cnt++;
            gg++;
        }
        
    }
    if(cnt<val)
        gg=-1;
    cout<<gg<<endl;
}
return 0;   

}

is things like things necessary for cp.

1 Like

Bro it is not necessary but everyone have their own style of writing code.
But these little things speed up during contest and u donā€™t need to write same thing again and again.
As @aryanc403 said read some basics about c++ templates.

After all
In good programming contest all that matters is logic and typing speedā€¦thatā€™s why tourist never uses c++ code template but still secures first positionā€¦

2 Likes

A Great Set of problems! But what to do when I get stuck on a problemā€¦ It has no solutions anywhere.

I read this discussion top to down and it seems by editorial you guys mean just the setter and tester solution? Is that correct?

1 Like

I guess so,
like they mean the template and seem intimidating to new coders.

The explanation could be made more simple like in a less mathematical way for some problems. :blush:

Mathematical way is the unambiguous way. I would really suggest everybody not to shy away from mathematics. Also, the editorialists usually provide intuition along with mathematics.

2 Likes

I think if Chef can include a video explaining about the approach then it would be the best way .
All will love it .

4 Likes

It wonā€™t be possible as there are so many problems. However often, people post their own video solution to difficult problems on discuss. Maybe you can search them.

Videos are easy to understand but it is good for basic ,you canā€™t expect everything explaining in a video.
You gotta accepte that the amount of content are more in reading materials.
However I also loved to have video editorial :smile:

1 Like