Check the following simple code for Parenting Partner :
*def solve(): n = int(raw_input()); a = [] for i in range(n):
s,e = map(int,raw_input().split()) a.append([s,e,i]) a.sort();
sch = [0]*n; x = -1; y = -1 for i in range(n): if a[i][0]<x:
if a[i][0]<y: return 'IMPOSSIBLE'
else: y = max(y,a[i][1]) sch[a[i][2]] = 'J'
else: x = max(x,a[i][1]) sch[a[i][2]] = 'C'
return ''.join(sch) for _ in range(int(raw_input())): print('Case #{}:
{}'.format(_+1,solve()))*
On Tue, Apr 7, 2020 at 6:35 AM Denys Halachian <[email protected]> wrote:
> 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].
> 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
> <https://groups.google.com/d/msgid/google-code/10B8115C-2D91-476C-8D49-EE3CF1BFBDCC%40gmail.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/CACsch8h2jjDKXFUyTtZgdZJd4W6DgLWp3y3h4RpEUfzaauKdNQ%40mail.gmail.com.