From bd258d299dd1c46f269d4256942a58c28e42f4fc Mon Sep 17 00:00:00 2001 From: yenru0 Date: Thu, 4 Mar 2021 07:12:50 +0900 Subject: [PATCH] complete 9251.py, 17298.py --- zeta_python/completed/17298.py | 26 ++++++++++++++++++++++++++ zeta_python/completed/9251.py | 15 +++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 zeta_python/completed/17298.py create mode 100644 zeta_python/completed/9251.py diff --git a/zeta_python/completed/17298.py b/zeta_python/completed/17298.py new file mode 100644 index 0000000..10283f6 --- /dev/null +++ b/zeta_python/completed/17298.py @@ -0,0 +1,26 @@ +def solve(N, A): + stack_i = [] + stack_v = [] + t = [-1] * N + + for i in range(N): + if not stack_v: + stack_v.append(A[i]) + stack_i.append(i) + else: + if A[i] > stack_v[-1]: + for j in range(len(stack_v) - 1, -1, -1): + if stack_v[j] < A[i]: + t[stack_i[j]] = A[i] + stack_v.pop() + stack_i.pop() + else: + break + stack_v.append(A[i]) + stack_i.append(i) + + return " ".join(map(str, t)) + + +if __name__ == '__main__': + print(solve(int(input()), list(map(int, input().split())))) diff --git a/zeta_python/completed/9251.py b/zeta_python/completed/9251.py new file mode 100644 index 0000000..01bf9a1 --- /dev/null +++ b/zeta_python/completed/9251.py @@ -0,0 +1,15 @@ +def solve(s1, s2): + N1 = len(s1) + N2 = len(s2) + T = [[0 for j in range(N2 + 1)] for i in range(N1 + 1)] + for i in range(1, N1 + 1): + for j in range(1, N2 + 1): + if s1[i - 1] == s2[j - 1]: + T[i][j] = T[i - 1][j - 1] + 1 + else: + T[i][j] = max((T[i][j - 1], T[i - 1][j])) + return T[-1][-1] + + +if __name__ == '__main__': + print(solve(input(), input()))