XD 
[20 char curse]
Isnât this O(n) in worst case ?
int ct[c]={}
Wait⌠if i initialize an array with an empty bracket shouldnât that by default initialize every element with zero in constant time?
Moreover if it does take O(N) time then why does sub-task 3 passes?
EDIT : Ok so i searched about it a bit, it turns out this is not a constant time operation (now
i feel like an idiot, that didnât knew a thing this basic, been using this all the time.
Though initializing like this will not take worse time than memset or loop, its usually faster then those two.
I still donât understand why does the 2nd ans 3rd subtask gives AC as the number of distinct elements ( = c in my program ) can be n/2 in worst case which makes this an q*n algo.
Is it ?
I just declared the array outside and used memset and time taken reduced from
3.88s to 1.26s
Will try removing memset later.
I still thinks itâs memset which requires optimization.
Let me try.
Itâs simple
âWeak test cases + strong optimizationsâ
XD
Yeah and you know who is author of that link ?
@aryanc403 himself 
He makes editorials in Russian using Google translate and then solve questions 
I am not sure about this though but one thing he does for sure
he addâs it to ârobot.txtâ so that you canât find it using Google 
Wtf!










OK so, what can i do to improve this? I am essentially using the same approach as the editorial, i replaced the array ct[] with a map but that increased the time instead.
Even though using map the complexity is Qân (compared to Qn using ct[] array), so i guess thatâs because of weak test cases.
Even though 1-3 subtask takes only 1.4sec or so last subtask times out.
Any help is appreciated.
Can anybody suggest me some good set of problems and solutions of Graphs/trees along with DP ? Video links would be of great help. 
If you have the time, then I have one more query 
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
) .
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
.
Thanks for your help mate!
Glad that I could help !!
Yup that is what I do generally

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.
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.
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âŚ