TLE??? same O(|S| +Q)
I did the same but got tle…why?? even used fast i/o and \n and all other things needed
#define ll long long
#define yes cout<<“YES”<<" “;
#define no cout<<“NO”<<endl
#define pb push_back
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i–)
#define mod 1000000007
#define f first
#define sec second
#define gcd(x,y) __gcd(x, y)
using namespace std;
even i changed all cin with scanf still got Tle…IT’s a serious issue…I guess
You have to initialise the map elements again other wise they will keep on increasing for other test cases. Hope that helps.
Yeah thats a big mistake thanks bro:+1:
Try replacing endl by “\n”. This worked for me
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].
Can anyone tell why i was getting tle??
from sys import stdin;
from collections import defaultdict
for i in range(t):
s = stdin.readline()
x, y = map(int, input().split())
up, down, left, right = 0, 0, 0, 0
for i in range(slen):
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.