Problem link : https://cses.fi/problemset/task/1194 Submission link: https://cses.fi/problemset/result/6625261/
I have done the problem in n*m which is the most optimised one, (1<=n,m<=10^3) . Even then I am getting TLE in one test case
Problem link : https://cses.fi/problemset/task/1194 Submission link: https://cses.fi/problemset/result/6625261/
I have done the problem in n*m which is the most optimised one, (1<=n,m<=10^3) . Even then I am getting TLE in one test case
Auto comment: topic has been updated by pratikshaw (previous revision, new revision, compare).
Start a BFS from E, and find shortest distance ($$$D_{N_{i}}$$$) to every node ($$$(N_{i}$$$) and if for any monster, there exists a ($$$D_{N_{i}}$$$) which is less than or equal to ($$$D_{N_{i}}$$$) from S to E, we can't reach the end point, otherwise we can.
Yeah I have done that. All cases have been accepted except for one which is giving TLE.
You can check this out. Hope it helps
I havent used maps , I have only used 2-D arrays
2-D arrays is much faster than maps, If u can implement my solution by replacing maps with 2-D arrays, then ur code's runtime would be lesser than mine and would get accepted at the very first try as I have to grind a lot to escape TLE.
It still isnt getting accepted. TLE is still there
your submission link isn't working, it's blank.
I guess CSES submission link is private-
include "bits/stdc++.h"
using namespace std;
define ll long long
int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, m; cin >> n >> m; vector<vector> arr(n, vector(m)); ll b = -1, c = -1; queue<pair<ll, ll>> q; vector<vector> visited(n, vector(m, false));
}
your code is pushing too many strings into a queue, which each of them are O(n), where n is the length of the string, and that's what makes your code slow. Your approach is totally fine, I guess. So you just need to change the last part of the code.
But I am pushing only those which are necessary, i think
You should learn Multi source BFS