For people who want the solution in C programming, refer: Competitive-Programming/Code-Chef/Help-Martha at master · strikersps/Competitive-Programming · GitHub
I added Fast IO. but i still get TLE. can anyone help me?
Solution - CodeChef: Practical coding for everyone
Edit: fixed it with ‘\n’ as someone suggested above.
Try initializing the variables in the map to 0 before performing mp[s[i]]++. That worked for me. Also, it should be “NO”, you have a typo[Maybe that’s the problem].
F
Can anyone tell why i was getting tle??
from sys import stdin;
from collections import defaultdict
t=int(input())
for i in range(t):
s = stdin.readline()
dict=defaultdict(int)
x, y = map(int, input().split())
up, down, left, right = 0, 0, 0, 0
slen=len(s)
for i in range(slen):
dict[s[i]]+=1
right=dict[“R”]
up=dict[“U”]
down=dict[“D”]
left=dict[“L”]
q = int(input())
for i in range(q):
a, b = map(int, input().split())
if 0 <= a - x <= right and 0 <= b - y <= up:
print("YES", a - x + b - y)
elif 0 <= x - a <= left and 0 <= y - b <= down:
print("YES", x - a + y - b)
elif 0 <= a - x <= right and 0 <= y - b <= down:
print("YES", a - x + y - b)
elif 0 <= x - a <= left and 0 <= b - y <= up:
print("YES", x - a + b - y)
else:
print("NO")
really… most of the people… I mean at least 50% people got it wrong just because of that “\n”.
F in the chats for this question please…
That not kind of fair!! At least they should have informed the participants about it before the contest!!
Consider the test input:
1
LUDLUDLUDLUD
1 2
2
2 3
1 -2
I literally wasted close to 1hr trying to figure out why the hell am i getting TLE even if i have used “\n” in place of “endl” and fastio methods…Then i submitted the same sol in c++17 instead of c++14 and it gets AC -_-.
I did same mistake man…
yeah that worked
Me neither. Literally there is no point of more than 1e7 chars input. I even submitted soln with this note. CodeChef: Practical coding for everyone
always use fast i/o methods. here is the code for fast i/o
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
this would take all input together and also print all the outputs together and save you from getting tle.
I figured out your mistake in the code check it out at the given link: edited code. Always try using “\n” for faster output using endl will take more time for big output.
When i coded in python i got tle but when i did in cpp i got AC? Why did this happen?
Tried that too…still same result.
Yup that was the typo problem, also i would like to mention that there is no need to initialise map elements to 0 explicitly, they are by default set to 0