From 6ebf2dd275833b9400a1008a59778f3916f95a64 Mon Sep 17 00:00:00 2001 From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Sat, 19 Nov 2022 15:52:44 -0500 Subject: [PATCH] 2014 S3 --- Main/Python/2014/S3.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Main/Python/2014/S3.py 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 + + -- 2.54.0