Getting TLE for DIGJUMP

i am not able to figure out why I am getting TLE β¦
https://www.codechef.com/viewsolution/33991461
this is my sol to problem
https://www.codechef.com/LRNDSA08/problems/DIGJUMP/

Canβt see your solution since it is technically part of a contest. Paste your code here instead

#include
#include
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool visited[100100]={0};
map<int,vector> mp;

ll bfs(ll v,ll N,string s){
queue q;
q.push(v);
visited[v]=true;
ll level = 0;
ll cq = 1;
ll iq = 0;
while(!q.empty()){
ll u = q.front();
q.pop();
if(u==N){
break;
}
for(auto x: mp[s[u]-β0β]){
if(!visited[x]){
visited[x]=1;
iq++;
q.push(x);
}
}
if(u>0 && !visited[u-1]){
visited[u-1] = 1;
iq++;
q.push(u-1);
}
if(u<N && !visited[u+1]){
visited[u+1] = 1;
iq++;
q.push(u+1);
}
cqβ;
if(cq == 0){
cq = iq;
iq=0;
level++;
}
}
return level;
}

int main() {
string s;
cin>>s;
ll N = s.length();
for(ll i=0;i<N;i++){
mp[s[i]-β0β].push_back(i);
}
cout<<bfs(0,N-1,s)<<"\n";

``````return 0;
``````

}

count1 =0
count2 =0
S
x=Si
for LOOP i>=N i++
if x=Si+1
count1=count1+1
x=S+1
for LOOP i>=N i++
if x<>Si+1
count2=count2+1
x=Si+1
MINIMAL JUMP= COUNT1+COUNT2

You can use start and end the code with this(```) to format your code.

1 Like