I hope its help,
from functools import reduce
class Solver(object):
def __init__(self):
super().__init__()
def find_distribution(self, intervals):
_intervals = list(intervals)
intervals.sort(key=lambda x: x[0])
mp = {}
J = 0
C = 0
for e in intervals:
tp = (e[0], e[1])
if tp not in mp:
mp[tp] = [0]
if J <= e[0]:
J = e[1]
mp[tp].append('J')
mp[tp][0] += 1
elif C <= e[0]:
C = e[1]
mp[tp].append('C')
mp[tp][0] += 1
else:
return 'IMPOSSIBLE'
sq = ''
for e in _intervals:
tp = (e[0], e[1])
sq += mp[tp][mp[tp][0]]
mp[tp][0] -= 1
return sq
def main():
solver = Solver()
T = int(input())
for t in range(T):
n = int(input())
intervals = []
for _ in range(n):
intervals.append([int(e) for e in input().split()])
print('Case #%d: %s' % (t + 1, solver.find_distribution(intervals)))
return 0
if __name__ == "__main__":
main()
> On Apr 4, 2020, at 11:54, Martin Seeler <[email protected]> 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]
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/d7192abb-1170-491e-9ad4-ac0d8f7978c7%40googlegroups.com
>
> <https://groups.google.com/d/msgid/google-code/d7192abb-1170-491e-9ad4-ac0d8f7978c7%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
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/10B8115C-2D91-476C-8D49-EE3CF1BFBDCC%40gmail.com.