From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Sat, 19 Nov 2022 20:52:44 +0000 (-0500) Subject: 2014 S3 X-Git-Url: http://git.skullheadx.com/nixos/tech/static/gitweb.js?a=commitdiff_plain;h=6ebf2dd275833b9400a1008a59778f3916f95a64;p=CCC.git 2014 S3 --- diff --git a/Main/Python/2014/S3.py b/Main/Python/2014/S3.py new file mode 100644 index 0000000..f7086d3 --- /dev/null +++ b/Main/Python/2014/S3.py @@ -0,0 +1,32 @@ +T = int(input()) +for test in range(T): + N = int(input()) + order = [] + for i in range(N): + car = int(input()) + order.append(car) + + branch = [] + next_ingredient = 1 + + while True: + if len(branch) == 0 and len(order) == 0: + print("Y") + break + + + if len(order) > 0 and next_ingredient == order[-1]: + next_ingredient += 1 + del order[-1] + elif len(branch) > 0 and branch[-1] == next_ingredient: + next_ingredient += 1 + del branch[-1] + else: + if len(order) > 0: + branch.append(order[-1]) + del order[-1] + else: + print("N") + break + +