From 3d8097d9ca9f5b094b7abef8cbbad073687c8b48 Mon Sep 17 00:00:00 2001 From: yenru0 Date: Tue, 24 Sep 2024 21:40:59 +0900 Subject: [PATCH] complete 30868.py and uncomplete 1717.py 1806.py 30869.py --- run.py | 0 zeta_python/1717.py | 26 ++++++++++++++++++++++ zeta_python/1806.py | 14 ++++++++++++ zeta_python/30869.py | 40 ++++++++++++++++++++++++++++++++++ zeta_python/completed/30868.py | 6 +++++ 5 files changed, 86 insertions(+) mode change 100644 => 100755 run.py create mode 100644 zeta_python/1717.py create mode 100644 zeta_python/1806.py create mode 100644 zeta_python/30869.py create mode 100644 zeta_python/completed/30868.py diff --git a/run.py b/run.py old mode 100644 new mode 100755 diff --git a/zeta_python/1717.py b/zeta_python/1717.py new file mode 100644 index 0000000..43b7856 --- /dev/null +++ b/zeta_python/1717.py @@ -0,0 +1,26 @@ +import sys + +input = sys.stdin.readline + + +def root(P, e): + node = e + while node != P[e]: + node = P[e] + return node + + +if __name__ == "__main__": + N, M = map(int, input().split()) + P = [i for i in range(N + 1)] + for _ in range(M): + op, a, b = map(int, input().split()) + if op == 0: # Merge + if a == b: + continue + rb, ra = root(P, b), root(P, a) + if rb != ra: + P[rb] = ra + print(P) + elif op == 1: # Find + print("YES" if a == b or root(P, a) == root(P, b) else "NO") diff --git a/zeta_python/1806.py b/zeta_python/1806.py new file mode 100644 index 0000000..913d0b6 --- /dev/null +++ b/zeta_python/1806.py @@ -0,0 +1,14 @@ +def p_sum(cumulative, left, right): + if 0 <= left <= right <= N: + return cumulative[right] - cumulative[left] + else: + return 100000000000000000000000000 + + +if __name__ == "__main__": + N, S = map(int, input().split()) + A: list[int] = list(map(int, input().split())) + CA: list[int] = [0] + + + print(right - left) diff --git a/zeta_python/30869.py b/zeta_python/30869.py new file mode 100644 index 0000000..362d4ad --- /dev/null +++ b/zeta_python/30869.py @@ -0,0 +1,40 @@ +import sys +import heapq + +input = sys.stdin.readline + +if __name__ == "__main__": + N, M, K = map(int, input().split()) + L = [[] for _ in range(M + 1)] + for _ in range(M): + s, e, t, g = map(int, input().split()) + L[s].append((e, t, g)) + res = 100000000000 + + D = [] + vis_tmp = [0] * (N + 1) + vis_tmp[1] = 1 + heapq.heappush( + D, + (0, 1, K, vis_tmp), + ) + while D: + now_t, now_stop, now_k, vis = heapq.heappop(D) + vis[now_stop] = 1 + if now_stop == N: + res = min(res, now_t) + break + + for e, t, g in L[now_stop]: + if vis_tmp[e]: + continue + if now_t % g == 0: + heapq.heappush(D, (now_t + t, e, now_k, vis.copy())) + else: + heapq.heappush(D, (now_t + -now_t % g + g + t, e, now_k, vis.copy())) + # 버스 소환술 사용 + if now_k >= 1: + heapq.heappush(D, (now_t + t, e, now_k - 1, vis.copy())) + else: + res = -1 + print(res) diff --git a/zeta_python/completed/30868.py b/zeta_python/completed/30868.py new file mode 100644 index 0000000..9d233f5 --- /dev/null +++ b/zeta_python/completed/30868.py @@ -0,0 +1,6 @@ +if __name__ == "__main__": + T = int(input()) + for i in range(T): + N = int(input()) + d, r = divmod(N, 5) + print(" ".join(["++++"] * d) + ((" " if d else "") + "|" * r if r else ""))