Yes, I solved in Python. Idea is simple, maintain a list of tuples. Each
tuple will have three values (start_time, end_time, index). now sort the
list based on first value. Checkout the code below.
for t in range(int(input())):
N = int(input())
A = []
for i in range(N):
s, e = map(int, input().split())
A.append((s, e, i))
A.sort()
ans = ['X'] * N
C, J = None, None
for x in A:
if C is not None:
if C[1] <= x[0]:
C = None
if J is not None:
if J[1] <= x[0]:
J = None
if C is None:
C = x
ans[x[2]] = "C"
elif J is None:
J = x
ans[x[2]] = "J"
else:
ans = "IMPOSSIBLE"
break
if 'X' in ans:
ans = "IMPOSSIBLE"
if isinstance(ans, list):
ans = "".join(ans)
print("Case #{}: {}".format(t+1, ans))
On Tuesday, 7 April 2020 06:20:28 UTC+5:30, Martin Seeler wrote:
>
> I'm asking to keep my sanity: Did anyone solve this problem with Python?
> I can't find these tricky edge cases where my code fails, all variations I
> try on my machine seem to work just fine. Still CodeJam Environment says
> *WA*.
>
> If there is someone who solved it in python, then I know I'm missing some
> cases. Otherwise I start to question the environment :D
>
> Thanks and have a nice day everyone
>
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/034a5111-e44e-4a02-8f8b-7d8791e89a7a%40googlegroups.com.