commit 8582780ac903258fc2d4fe5e635d62d7c9680127 Author: Justin Lin Date: Sat May 2 15:42:52 2026 +1000 commit diff --git a/coconut/coconut.py b/coconut/coconut.py new file mode 100644 index 0000000..5892610 --- /dev/null +++ b/coconut/coconut.py @@ -0,0 +1,15 @@ +n, k = map(int, input().split(" ")) +arr = [int(x) for x in input().strip().split()] + +arr.sort() + +pairs = 0 +i = 0 +while i < n - 1: + if arr[i + 1] - arr[i] <= k: + pairs += 1 + i += 2 + else: + i += 1 + +print(pairs) diff --git a/coconut/input_1 b/coconut/input_1 new file mode 100644 index 0000000..b1c5b33 --- /dev/null +++ b/coconut/input_1 @@ -0,0 +1,2 @@ +6 2 +1 3 5 2 4 6 diff --git a/coconut/input_2 b/coconut/input_2 new file mode 100644 index 0000000..914cf00 --- /dev/null +++ b/coconut/input_2 @@ -0,0 +1,2 @@ +5 1 +1 5 3 2 4 diff --git a/coconut/input_3 b/coconut/input_3 new file mode 100644 index 0000000..cb519af --- /dev/null +++ b/coconut/input_3 @@ -0,0 +1,2 @@ +7 0 +1 3 1 2 2 5 4 diff --git a/e/input_1 b/e/input_1 new file mode 100644 index 0000000..670aec6 --- /dev/null +++ b/e/input_1 @@ -0,0 +1,7 @@ +5 4 +1 5 +1 2 3 4 5 +1 2 1 +1 3 2 +4 2 3 +5 4 7 diff --git a/e/input_2 b/e/input_2 new file mode 100644 index 0000000..e210098 --- /dev/null +++ b/e/input_2 @@ -0,0 +1,12 @@ +6 9 +3 4 +2 17 8 6 9 3 +1 2 6 +1 3 10 +1 4 21 +2 3 5 +2 5 7 +3 6 11 +4 5 31 +4 6 4 +5 6 28 diff --git a/e/restaurant.py b/e/restaurant.py new file mode 100644 index 0000000..64a3dbb --- /dev/null +++ b/e/restaurant.py @@ -0,0 +1,51 @@ +import math +from queue import PriorityQueue + + +def read_idx(x: str): + return int(x) - 1 + + +def inputs() -> list[str]: + return input().strip(" ").split(" ") + + +V, E = map(int, inputs()) +s, t = map(read_idx, inputs()) +vw = list(map(int, inputs())) # vertex weight +graph = [[] for _ in range(V)] +for _ in range(E): + u, v, w = map(read_idx, inputs()) + w += 1 + graph[u].append((v, w)) + graph[v].append((u, w)) + +newgraph = [[] for _ in range(V)] + +for u in range(V): + for v, w in graph[u]: + newgraph[u].append((v, vw[u] + w)) + + +def dijstra(g: list[list[tuple[int, int]]], s: int, t: int) -> float: + dist = [math.inf] * V + dist[s] = 0 + q = PriorityQueue() + q.put((0, s)) + while not q.empty(): + d, u = q.get() + if d != dist[u]: + continue + + # print(u, d) + for v, w in g[u]: + if dist[v] > dist[u] + w: + dist[v] = dist[u] + w + q.put((dist[v], v)) + + return dist[t] + + +# print(vw, graph) +# print(newgraph) +print(dijstra(newgraph, s, t)) diff --git a/light/input_1 b/light/input_1 new file mode 100644 index 0000000..e76db1d --- /dev/null +++ b/light/input_1 @@ -0,0 +1,2 @@ +3 +8 6 7 diff --git a/light/input_2 b/light/input_2 new file mode 100644 index 0000000..2072ff9 --- /dev/null +++ b/light/input_2 @@ -0,0 +1,2 @@ +5 +4 4 1 9 2 diff --git a/light/input_3 b/light/input_3 new file mode 100644 index 0000000..4f88743 --- /dev/null +++ b/light/input_3 @@ -0,0 +1,2 @@ +1 +1000 diff --git a/light/light.py b/light/light.py new file mode 100644 index 0000000..8e094c1 --- /dev/null +++ b/light/light.py @@ -0,0 +1,14 @@ +n = int(input()) +suspects = [int(x) for x in input().strip().split(" ")] +suspects.sort(reverse=True) + +if n > 1: + result = 0 + sums = [suspects[0]] + for i in range(1, n): + sums.append(sums[-1] + suspects[i]) + + result = sum(sums[1:]) + print(result) +else: + print(suspects[0]) diff --git a/peak/input_1 b/peak/input_1 new file mode 100644 index 0000000..99e00b5 --- /dev/null +++ b/peak/input_1 @@ -0,0 +1,2 @@ +3 +1 2 3 diff --git a/peak/input_2 b/peak/input_2 new file mode 100644 index 0000000..18a4d51 --- /dev/null +++ b/peak/input_2 @@ -0,0 +1,2 @@ +4 +1 2 3 4 diff --git a/peak/input_3 b/peak/input_3 new file mode 100644 index 0000000..823123c --- /dev/null +++ b/peak/input_3 @@ -0,0 +1,2 @@ +5 +10 20 30 40 50 diff --git a/peak/peak.py b/peak/peak.py new file mode 100644 index 0000000..3ed9650 --- /dev/null +++ b/peak/peak.py @@ -0,0 +1,5 @@ +n = int(input()) +input() # ignore the numbers + +ans = 2 ** (n - 1) - 2 +print(max(ans, 0) % 998244353) diff --git a/picky/input_1 b/picky/input_1 new file mode 100644 index 0000000..bf7e96f --- /dev/null +++ b/picky/input_1 @@ -0,0 +1,4 @@ +3 10 10 +2 2 20 +5 2 0 +1 2 12 diff --git a/picky/input_2 b/picky/input_2 new file mode 100644 index 0000000..9866664 --- /dev/null +++ b/picky/input_2 @@ -0,0 +1,3 @@ +2 0 0 +1 2 4 +2 1 4 diff --git a/picky/input_3 b/picky/input_3 new file mode 100644 index 0000000..5863b99 --- /dev/null +++ b/picky/input_3 @@ -0,0 +1,3 @@ +2 0 4 +1 1 5 +0 3 5 diff --git a/picky/input_4 b/picky/input_4 new file mode 100644 index 0000000..e69de29 diff --git a/picky/picky.py b/picky/picky.py new file mode 100644 index 0000000..10e9561 --- /dev/null +++ b/picky/picky.py @@ -0,0 +1,80 @@ +import math +import sys + +sys.setrecursionlimit(100000) + + +def inputs(): + return map(int, input().strip().split(" ")) + + +n, wet_c, dry_c = inputs() + +costs = [[(math.inf, -1)] * (dry_c + 1) for _ in range(wet_c + 1)] +costs[0][0] = (0, -1) + +bundles = [] +for i in range(n): + wet, dry, cost = inputs() + bundles.append((wet, dry, cost)) + if wet <= wet_c and dry <= dry_c: + costs[wet][dry] = (cost, i) + + +def get_cost(w, d) -> float: + if w == 0 and d == 0: + return 0 + + if w < 0 or d < 0: + return math.inf + + if costs[w][d][1] != -1: + print("reusing: ", w, d) + return costs[w][d][0] + + print(w, d) + + for i in range(len(bundles)): + wet, dry, cost = bundles[i] + new_cost = get_cost(w - wet, d - dry) + cost + if costs[w][d][0] > new_cost: + costs[w][d] = (new_cost, i) + return costs[w][d][0] + + +def bottom_up() -> float: + for w in range(wet_c + 1): + for d in range(dry_c + 1): + for i in range(len(bundles)): + wet, dry, cost = bundles[i] + if wet > w or dry > d: + continue + new_cost = costs[w - wet][d - dry][0] + cost + if costs[w][d][0] > new_cost: + costs[w][d] = (new_cost, i) + + return costs[wet_c][dry_c][0] + + +def backtrack(w, d) -> list[int]: + counter = [0] * n + b = costs[w][d][1] + while b != -1: + counter[b] += 1 + wet, dry, _ = bundles[b] + w -= wet + d -= dry + b = costs[w][d][1] + return counter + + +# c = get_cost(wet_c, dry_c) +c = bottom_up() +# print(costs) +if math.isinf(c): + print(-1) +else: + print(c) + + for c in backtrack(wet_c, dry_c): + print(c) diff --git a/q2/q2.py b/q2/q2.py new file mode 100644 index 0000000..64fdb52 --- /dev/null +++ b/q2/q2.py @@ -0,0 +1,25 @@ +a, b = map(int, input().split(" ")) + +memo = {} + + +def win(i: int, j: int) -> bool: + # print(f"kirby: {i}, {j}") + if i < j: + return win(j, i) + + if j == 1: + return True + if j <= 0: + return False + if (i, j) in memo: + return memo[(i, j)] + + memo[(i, j)] = not win(i - 1, j) or not win(i, j - 1) + return memo[(i, j)] + + +if win(a, b): + print("Kirby") +else: + print("Dedede") diff --git a/q2/q2_test.sh b/q2/q2_test.sh new file mode 100755 index 0000000..9248818 --- /dev/null +++ b/q2/q2_test.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +echo "0 2" | python q2.py +echo "expected: Dedede" + +echo "1 2" | python q2.py +echo "expected: Kirby" + +echo "1 2" | python q2.py +echo "expected: Kirby" + +echo "2 2" | python q2.py +echo "expected: Dedede" + +echo "4 2" | python q2.py +echo "expected: Dedede" + +echo "1 50" | python q2.py +echo "expected: Kirby" + +echo "2 3" | python q2.py +echo "expected: Kirby" + +echo "4 3" | python q2.py +echo "expected: Kirby" + +echo "5 2" | python q2.py +echo "expected: Kirby" diff --git a/sabzeh/input_1 b/sabzeh/input_1 new file mode 100644 index 0000000..69010fb --- /dev/null +++ b/sabzeh/input_1 @@ -0,0 +1 @@ +5 2 diff --git a/sabzeh/input_2 b/sabzeh/input_2 new file mode 100644 index 0000000..0f64a0c --- /dev/null +++ b/sabzeh/input_2 @@ -0,0 +1 @@ +5 4 diff --git a/sabzeh/sabzeh.py b/sabzeh/sabzeh.py new file mode 100644 index 0000000..e9685b6 --- /dev/null +++ b/sabzeh/sabzeh.py @@ -0,0 +1,4 @@ +length, n = map(int, input().split(" ")) + +ans = max(2 * n - length - 1, 0) +print(ans) diff --git a/sample/banana_1.py b/sample/banana_1.py new file mode 100644 index 0000000..ad4ba94 --- /dev/null +++ b/sample/banana_1.py @@ -0,0 +1,7 @@ +import math + +n, c = map(int, input().split()) +a = [int(input()) for _ in range(n)] + +packs = math.ceil(sum(a) / 10) +print(packs * c) diff --git a/sample/banana_input b/sample/banana_input new file mode 100644 index 0000000..0f105b1 --- /dev/null +++ b/sample/banana_input @@ -0,0 +1,5 @@ +4 6 +15 +8 +31 +42 diff --git a/sample/freq_flyer.py b/sample/freq_flyer.py new file mode 100644 index 0000000..fc1f981 --- /dev/null +++ b/sample/freq_flyer.py @@ -0,0 +1,18 @@ +n = int(input()) +f = [input() for _ in range(n)] +# Continue your code here and print your final answer! +counts = {} +for l in f: + if l in counts: + counts[l] += 1 + else: + counts[l] = 1 + +mk = "" +ma = -1 +for k in counts: + if counts[k] > ma or (counts[k] == ma and k < mk): + mk = k + ma = counts[k] + +print(mk) diff --git a/sample/input_freq_flyer b/sample/input_freq_flyer new file mode 100644 index 0000000..99c4cda --- /dev/null +++ b/sample/input_freq_flyer @@ -0,0 +1,11 @@ +10 +japan +hongkong +japan +hongkong +france +germany +france +germany +japan +japan diff --git a/sample/input_meow b/sample/input_meow new file mode 100644 index 0000000..367bc01 --- /dev/null +++ b/sample/input_meow @@ -0,0 +1,8 @@ +7 +hisss +triiilll +buuurrrbllle +his +trlll +burbble +hello diff --git a/sample/meow.py b/sample/meow.py new file mode 100644 index 0000000..15b9fbc --- /dev/null +++ b/sample/meow.py @@ -0,0 +1,21 @@ +import re + +t = int(input()) +a = [input() for _ in range(t)] +# Continue your code here and print your final answer! +patterns = { + "hiss": re.compile("^hiss+$"), + "trill": re.compile("^tri+ll+$"), + "burble": re.compile("^bu+r+bl+e$"), +} + + +for line in a: + found = False + for name in patterns: + if patterns[name].match(line): + print(name) + found = True + break + if not found: + print("human noises") diff --git a/sample/odd_even_char.py b/sample/odd_even_char.py new file mode 100644 index 0000000..f4172d1 --- /dev/null +++ b/sample/odd_even_char.py @@ -0,0 +1,14 @@ +n = int(input()) +s = input() +# Continue your code here and print your final answer! + +odd_evens = [ord(c) % 2 for c in list(s)] +odd = 0 +even = 0 +for x in odd_evens: + if x == 1: + odd += 1 + else: + even += 1 + +print(odd, even) diff --git a/season/input_1 b/season/input_1 new file mode 100644 index 0000000..8b5da22 --- /dev/null +++ b/season/input_1 @@ -0,0 +1,23 @@ +11 +1 +1 2 3 4 +1 +1 3 4 2 +2 +1 2 3 4 4 3 2 1 +1 +1 1 1 3 +1 +1 7 7 2 +1 +7 7 2 1 +1 +7 7 1 2 +1 +1 1 7 2 +1 +1 1 2 2 +1 +1 4 1 2 +3 +1 2 3 3 2 1 4 5 6 1 1 1 diff --git a/season/season.py b/season/season.py new file mode 100644 index 0000000..aa0b599 --- /dev/null +++ b/season/season.py @@ -0,0 +1,59 @@ +import math + +n = int(input()) + +ks = [0] * n +temp = [] +for i in range(n): + k = int(input()) + ks[i] = k + temp.append(list(map(int, input().strip().split(" ")))) + +# print(ks, temp) + + +def four_season(k: int, temp: list[int]) -> bool: + # print(k, temp) + max_i = -1 + max_v = -math.inf + min_i = -1 + min_v = math.inf + + if len(temp) == 4: + for i in range(len(temp)): + v = temp[i] + if v > max_v: + max_i = i + max_v = v + if v < min_v: + min_i = i + min_v = v + + # print(max_i, max_v, min_i, min_v) + if temp[min_i - 2 % 4] == max_v: + return True + if temp[max_i - 2 % 4] == min_v: + return True + return False + + for i in range(k): + new_temp = [0] * 4 + for j in range(len(temp)): + idx = (i + j) % len(temp) + # print(temp, idx) + new_temp[j // k] += temp[idx] + # print(new_temp) + if four_season(1, new_temp): + return True + + return False + + +for i in range(n): + if len(temp[i]) / ks[i] != 4: + print("No") + continue + if four_season(ks[i], temp[i]): + print("Yes") + else: + print("No") diff --git a/steak/input_1 b/steak/input_1 new file mode 100644 index 0000000..dc4fe35 --- /dev/null +++ b/steak/input_1 @@ -0,0 +1,8 @@ +0 0 0 +0 0 1 +0 1 0 +1 0 0 +0 1 1 +1 0 1 +1 1 0 +1 1 1 diff --git a/steak/input_2 b/steak/input_2 new file mode 100644 index 0000000..128d309 --- /dev/null +++ b/steak/input_2 @@ -0,0 +1,8 @@ +0 4 0 +3 0 0 +3 0 6 +7 3 6 +7 3 0 +4 7 0 +0 4 6 +4 7 6 diff --git a/steak/steak.py b/steak/steak.py new file mode 100644 index 0000000..a97193f --- /dev/null +++ b/steak/steak.py @@ -0,0 +1,7 @@ +sum_x = 0 + +for i in range(8): + x, _, _ = map(int, input().strip().split(" ")) + sum_x += x + +print(sum_x / 8) diff --git a/tea b/tea new file mode 100644 index 0000000..e69de29