diff --git a/29-01-24/division.py b/2024/01/29-01-24/division.py similarity index 100% rename from 29-01-24/division.py rename to 2024/01/29-01-24/division.py diff --git a/29-01-24/football.py b/2024/01/29-01-24/football.py similarity index 100% rename from 29-01-24/football.py rename to 2024/01/29-01-24/football.py diff --git a/29-01-24/gratitude.py b/2024/01/29-01-24/gratitude.py similarity index 100% rename from 29-01-24/gratitude.py rename to 2024/01/29-01-24/gratitude.py diff --git a/29-01-24/improve_it.py b/2024/01/29-01-24/improve_it.py similarity index 100% rename from 29-01-24/improve_it.py rename to 2024/01/29-01-24/improve_it.py diff --git a/29-01-24/king_escape.py b/2024/01/29-01-24/king_escape.py similarity index 100% rename from 29-01-24/king_escape.py rename to 2024/01/29-01-24/king_escape.py diff --git a/29-01-24/king_escape2.py b/2024/01/29-01-24/king_escape2.py similarity index 100% rename from 29-01-24/king_escape2.py rename to 2024/01/29-01-24/king_escape2.py diff --git a/29-01-24/lights.py b/2024/01/29-01-24/lights.py similarity index 100% rename from 29-01-24/lights.py rename to 2024/01/29-01-24/lights.py diff --git a/29-01-24/magic.py b/2024/01/29-01-24/magic.py similarity index 100% rename from 29-01-24/magic.py rename to 2024/01/29-01-24/magic.py diff --git a/29-01-24/stages.py b/2024/01/29-01-24/stages.py similarity index 100% rename from 29-01-24/stages.py rename to 2024/01/29-01-24/stages.py diff --git a/29-01-24/sujet.pdf b/2024/01/29-01-24/sujet.pdf similarity index 100% rename from 29-01-24/sujet.pdf rename to 2024/01/29-01-24/sujet.pdf diff --git a/29-01-24/sum.c b/2024/01/29-01-24/sum.c similarity index 100% rename from 29-01-24/sum.c rename to 2024/01/29-01-24/sum.c diff --git a/29-01-24/sum.py b/2024/01/29-01-24/sum.py similarity index 100% rename from 29-01-24/sum.py rename to 2024/01/29-01-24/sum.py diff --git a/2024/02/05-02-24/a.py b/2024/02/05-02-24/a.py new file mode 100644 index 0000000..2d7e33c --- /dev/null +++ b/2024/02/05-02-24/a.py @@ -0,0 +1,38 @@ +def score2(elems): + count = sum(elems) + total = 0 + allowed = count-(count//4) + for i in range(100, -1, -1): + if allowed > elems[i]: + total += i*elems[i] + allowed -= elems[i] + else: + total += i*allowed + return total + return total + + +def main(): + ct = int(input()) + + for _ in range(ct): + input() + me_ = [int(i) for i in input().split()] + other_ = [int(i) for i in input().split()] + + me = [0 for i in range(101)] + other = [0 for i in range(101)] + + for i in range(len(me_)): + me[me_[i]] += 1 + other[other_[i]] += 1 + + i=0 + while score2(me) < score2(other): + me[100] += 1 + other[0] += 1 + i+=1 + + print(i) + +main() diff --git a/2024/02/05-02-24/b.py b/2024/02/05-02-24/b.py new file mode 100644 index 0000000..b301d6b --- /dev/null +++ b/2024/02/05-02-24/b.py @@ -0,0 +1,19 @@ +import bisect + +def main(): + n_tests = int(input()) + + for _ in range(n_tests): + n, m = [int(i) for i in input().split()] + ai = [int(i) for i in input().split()] + bj = [int(i) for i in input().split()] + + ai.sort() + + for i in range(m): + tmp = ai.pop(0) + bisect.insort(ai, bj[i]) + + print(sum(ai)) + +main() \ No newline at end of file diff --git a/2024/02/05-02-24/c.py b/2024/02/05-02-24/c.py new file mode 100644 index 0000000..bcaf2c2 --- /dev/null +++ b/2024/02/05-02-24/c.py @@ -0,0 +1,35 @@ +import sys + +def ask(a): + print(a) + sys.stdout.flush() + return int(input()) + +def main(): + # max distance, size of p + m, n = [int(i) for i in input().split()] + + answers = [] + for i in range(n): + a = ask(m) + if a == 0: + return + answers.append(a) + + asked = n + ppos = 0 + lower, upper = 1, m-1 + while asked < 60: + curr = lower + (upper-lower)//2 + a = ask(curr) + asked += 1 + if a*answers[ppos%n] == 1: + upper = curr -1 + elif a*answers[ppos%n] == -1: + lower = curr +1 + else: + return + ppos += 1 + + +main() diff --git a/2024/02/05-02-24/d.py b/2024/02/05-02-24/d.py new file mode 100644 index 0000000..65baa02 --- /dev/null +++ b/2024/02/05-02-24/d.py @@ -0,0 +1,53 @@ +from functools import cache +import bisect +import sys + +base_limit = sys.getrecursionlimit() + +def sc(cons): + return (cons*(cons+1))/2 + +def brutetop(a, b, k): + first = {} + for i in range(len(a)): + if a[i] not in first and a[i] != b[i]: + first[a[i]] = i + @cache + def brute(Q, i, cons): + if i == len(a): + return sc(cons) + + if a[i] == b[i] or a[i] in Q: + return brute(Q, i+1, cons+1) + + if len(Q) < k and (a[i] in first and i == first[a[i]]): + Qcop = list(Q) + bisect.insort(Qcop, a[i]) + + res1 = brute(Q, i+1, 0) + sc(cons) + res2 = brute(tuple(Qcop), i+1, cons+1) + + return max(res1, res2) + + return brute(Q, i+1, 0) + sc(cons) + + return brute((), 0, 0) + +def main(): + ct = int(input()) + ress = [] + + for _ in range(ct): + # len(a, b), char lim + n, k = [int(i) for i in input().split()] + a = input() # a = base string + b = input() # b = objective + + sys.setrecursionlimit(max(len(a), base_limit)) + print(int(brutetop(a, b, k))) + #ress.append(str(int(brutetop(a, b, k)))) + #print("\n".join(ress)) + + + +main() diff --git a/2024/02/05-02-24/fuzzing_d.py b/2024/02/05-02-24/fuzzing_d.py new file mode 100644 index 0000000..f262169 --- /dev/null +++ b/2024/02/05-02-24/fuzzing_d.py @@ -0,0 +1,14 @@ +import random +from string import ascii_lowercase + +def rand_letters(a): + return "".join(random.choices(ascii_lowercase[:10], k=a)) + +count = 5 +print(count) +for i in range(count): + size = random.randint(0, 100000) + repl = random.randint(0, 10) + print(size, repl) + print(rand_letters(size)) + print(rand_letters(size)) diff --git a/2024/02/05-02-24/sujet.pdf b/2024/02/05-02-24/sujet.pdf new file mode 100644 index 0000000..e6ff2fa Binary files /dev/null and b/2024/02/05-02-24/sujet.pdf differ diff --git a/2024/02/12-02-24/a.py b/2024/02/12-02-24/a.py new file mode 100644 index 0000000..d2e43e1 --- /dev/null +++ b/2024/02/12-02-24/a.py @@ -0,0 +1,74 @@ +def product(l): + if l == []: + return 1 + return l[0]*product(l[1:]) + + +def once(): + input() + ai = [int(i) for i in input().split()] + + ai_p = [a for a in ai if a > 0] + ai_n = [a for a in ai if a < 0] + contains0 = (0 in ai) + + ai_p.sort(reverse=True) + ai_n.sort() + + if ai_p == []: # all neg or null + if contains0: + return 0 + return product(ai_n[-5:]) + + elif len(ai_n)+len(ai_p) < 5: + return product(ai) + elif len(ai_n)+len(ai_p) == 5: + p = product(ai_n)*product(ai_p) + if p < 0 and contains0: + return 0 + return p + else: + # selected = [ai_p[0]] + i_n = 0 + i_p = 1 + prod = ai_p[0] + + for _ in range(2): + if i_n + 2 > len(ai_n) and i_p + 2 <= len(ai_p): + prod *= ai_p[i_p]*ai_p[i_p+1] + # selected.append(ai_p[i_p]) + # selected.append(ai_p[i_p+1]) + i_p+=2 + elif i_p + 2 > len(ai_p) and i_n + 2 <= len(ai_n): + prod *= ai_n[i_n]*ai_n[i_n+1] + # selected.append(ai_n[i_n]) + # selected.append(ai_n[i_n+1]) + i_n+=2 + elif i_p +1 == len(ai_p) and i_n+1 == len(ai_n): + prod *= ai_p[-1]*ai_n[-1] + else: + pp = ai_p[i_p]*ai_p[i_p+1] + pn = ai_n[i_n]*ai_n[i_n+1] + + if pp > pn: + prod *= pp + # selected.append(ai_p[i_p]) + # selected.append(ai_p[i_p+1]) + i_p += 2 + else: + prod *= pn + # selected.append(ai_n[i_n]) + # selected.append(ai_n[i_n+1]) + i_n += 2 + return prod + + +def main(): + count = int(input()) + + for _ in range(count): + print(once()) + + + +main() diff --git a/2024/02/12-02-24/b.py b/2024/02/12-02-24/b.py new file mode 100644 index 0000000..20bfc13 --- /dev/null +++ b/2024/02/12-02-24/b.py @@ -0,0 +1,27 @@ +def solve(): + n = int(input()) + env = input() + + winners_ct = [1] + t = env[0] + ind, k = 1, 1 + for i in range(1, len(env)): + new = env[i] + if new == t: + k += 1 + winners_ct.append(winners_ct[-1]) + else: + winners_ct.append(winners_ct[-1]+k) + k = 1 + t = new + return " ".join([str(a) for a in winners_ct]) + + +def main(): + count = int(input()) + + for _ in range(count): + print(solve()) + + +main() \ No newline at end of file diff --git a/2024/02/12-02-24/c.py b/2024/02/12-02-24/c.py new file mode 100644 index 0000000..e69de29 diff --git a/2024/02/12-02-24/fuzzing_a.py b/2024/02/12-02-24/fuzzing_a.py new file mode 100644 index 0000000..ec1f346 --- /dev/null +++ b/2024/02/12-02-24/fuzzing_a.py @@ -0,0 +1,7 @@ +import random + +print(50) +for i in range(50): + size = random.randint(5, 10) + print(size) + print(" ".join([str(random.randint(-100, 100)) for _ in range(size)])) \ No newline at end of file diff --git a/19-02-24/a.cpp b/2024/02/19-02-24/a.cpp similarity index 100% rename from 19-02-24/a.cpp rename to 2024/02/19-02-24/a.cpp diff --git a/19-02-24/b.py b/2024/02/19-02-24/b.py similarity index 100% rename from 19-02-24/b.py rename to 2024/02/19-02-24/b.py diff --git a/2024/02/19-02-24/c.py b/2024/02/19-02-24/c.py new file mode 100644 index 0000000..1db36f7 --- /dev/null +++ b/2024/02/19-02-24/c.py @@ -0,0 +1,49 @@ +def min_new(a, m): + while m in a: + m+=1 + return m + +def max_new(a: set[int], m): + while m in a: + m-=1 + + return m + +def get_minimal(a, n): + used = set(a) + if len(used) != len(a): + return [-1] + + arr = [] + for i in range(n//2): + m = max_new(used, a[i]) + used.add(m) + if m <= 0: + return [-1] + + arr.append(m) + + for i in range(n//2): + for j in range(i, n//2): + if arr[j] < arr[i] and arr[i] < a[j]: + tmp = arr[j] + arr[j] = arr[i] + arr[i] = tmp + + return arr + +# Réécrire en c++ +def main(): + ct = int(input()) + + for i in range(ct): + n = int(input()) + a = [int(b) for b in input().split()] + + arr = get_minimal(a, n) + if arr == [-1]: + print(-1) + else: + print(" ".join([str(arr[i])+" "+str(a[i]) for i in range(len(arr))])) + +main() diff --git a/04-03-24/a.py b/2024/03/04-03-24/a.py similarity index 100% rename from 04-03-24/a.py rename to 2024/03/04-03-24/a.py diff --git a/04-03-24/b.py b/2024/03/04-03-24/b.py similarity index 100% rename from 04-03-24/b.py rename to 2024/03/04-03-24/b.py diff --git a/04-03-24/c.py b/2024/03/04-03-24/c.py similarity index 100% rename from 04-03-24/c.py rename to 2024/03/04-03-24/c.py diff --git a/04-03-24/d.py b/2024/03/04-03-24/d.py similarity index 100% rename from 04-03-24/d.py rename to 2024/03/04-03-24/d.py diff --git a/04-03-24/sujet.pdf b/2024/03/04-03-24/sujet.pdf similarity index 100% rename from 04-03-24/sujet.pdf rename to 2024/03/04-03-24/sujet.pdf diff --git a/11-03-24/a.py b/2024/03/11-03-24/a.py similarity index 100% rename from 11-03-24/a.py rename to 2024/03/11-03-24/a.py diff --git a/2024/03/11-03-24/a2.py b/2024/03/11-03-24/a2.py new file mode 100644 index 0000000..4c5b892 --- /dev/null +++ b/2024/03/11-03-24/a2.py @@ -0,0 +1,38 @@ +def repr(uf, i): + if uf[i] == i: + return i + uf[i] = repr(uf, uf[i]) + return uf[i] + +def union(uf, val, i, j): + ri = repr(uf, i) + rj = repr(uf, j) + + uf[rj] = ri + val[ri] = val[rj] = min(val[ri], val[rj]) + + +def main(): + [n, k] = [int(i) for i in input().split()] + a = [int(i) for i in input().split()] + + couples = [[int(i)-1 for i in input().split()] for _ in range(k)] + + uf = [i for i in range(n)] + val = [a[i] for i in range(n)] + + for (i, j) in couples: + ri = repr(uf, i) + rj = repr(uf, j) + if ri != rj: + union(uf, val, i, j) + + mini = 0 + for i in range(n): + if repr(uf, i) == i: + mini += val[i] + + return mini + + +print(main()) diff --git a/11-03-24/b.py b/2024/03/11-03-24/b.py similarity index 100% rename from 11-03-24/b.py rename to 2024/03/11-03-24/b.py diff --git a/11-03-24/c.py b/2024/03/11-03-24/c.py similarity index 100% rename from 11-03-24/c.py rename to 2024/03/11-03-24/c.py diff --git a/2024/03/11-03-24/d.py b/2024/03/11-03-24/d.py new file mode 100644 index 0000000..fa5cbce --- /dev/null +++ b/2024/03/11-03-24/d.py @@ -0,0 +1,46 @@ +def main(): + n, m = [int(i) for i in input().split()] + uv = [[int(i) for i in input().split()] for i in range(m)] + + if m==n*(n-1)/2: + print(3) + out = [] + u, v = uv[0] + for a, b in uv: + if (a, b) == (u, v): + out.append(1) + elif a==u or b==u: + out.append(2) + else: + out.append(3) + return " ".join([str(i) for i in out]) + + # Trouver un sommet de degré != n-1 + degs = [0 for _ in range(n)] + + for u, v in uv: + degs[u-1] += 1 + degs[v-1] += 1 + + j=-1 + for i in range(n): + if degs[i] < n-1: + j = i+1 + break + if j==-1: + return + + + + print(2) + out = [] + for u, v in uv: + if u==j or v==j: + out.append(2) + else: + out.append(1) + + return " ".join([str(i) for i in out]) + +for _ in range(int(input())): + print(main()) \ No newline at end of file diff --git a/2024/03/11-03-24/fuzzing_b.py b/2024/03/11-03-24/fuzzing_b.py new file mode 100644 index 0000000..d2a59d4 --- /dev/null +++ b/2024/03/11-03-24/fuzzing_b.py @@ -0,0 +1,21 @@ +import random + +LENGTH=1 + +print(LENGTH) +for _ in range(LENGTH): + n = random.randint(1, 200000) + n = 200000 + print(n) + root = random.randint(1, n) + l = [] + for i in range(n): + if i==root: + l.append(str(root)) + else: + j = i + while i==j: + j=random.randint(1, n) + l.append(str(j)) + + print(" ".join(l)) \ No newline at end of file diff --git a/18-03-24/a.py b/2024/03/18-03-24/a.py similarity index 100% rename from 18-03-24/a.py rename to 2024/03/18-03-24/a.py diff --git a/18-03-24/b.py b/2024/03/18-03-24/b.py similarity index 100% rename from 18-03-24/b.py rename to 2024/03/18-03-24/b.py diff --git a/18-03-24/c.py b/2024/03/18-03-24/c.py similarity index 100% rename from 18-03-24/c.py rename to 2024/03/18-03-24/c.py diff --git a/18-03-24/d.py b/2024/03/18-03-24/d.py similarity index 100% rename from 18-03-24/d.py rename to 2024/03/18-03-24/d.py diff --git a/25-03-24/a.py b/2024/03/25-03-24/a.py similarity index 100% rename from 25-03-24/a.py rename to 2024/03/25-03-24/a.py diff --git a/25-03-24/b.py b/2024/03/25-03-24/b.py similarity index 100% rename from 25-03-24/b.py rename to 2024/03/25-03-24/b.py diff --git a/2024/03/25-03-24/c.py b/2024/03/25-03-24/c.py new file mode 100644 index 0000000..c76c188 --- /dev/null +++ b/2024/03/25-03-24/c.py @@ -0,0 +1,36 @@ +n = int(input()) +points = [tuple(map(int, input().split())) for _ in range(n)] + +p1 = points[0] +d_min = float("inf") +p_min = -2 + +def dist(pa, pb): + return (pb[0]-pa[0])*(pb[0]-pa[0]) + (pb[1]-pa[1])*(pb[1]-pa[1]) + +i2 = min((i for i in range(1, n)), key=lambda x:dist(p1, points[x])) +p2 = points[i2] + +def aligned(p1, p2, p3): + # Extract coordinates of points + x1, y1 = p1 + x2, y2 = p2 + x3, y3 = p3 + + # Calculate slopes of lines formed by pairs of points + slope1 = (y2 - y1) / (x2 - x1) if x2 - x1 != 0 else float('inf') + slope2 = (y3 - y2) / (x3 - x2) if x3 - x2 != 0 else float('inf') + + # Check if slopes are equal (i.e., points are aligned) + return slope1 == slope2 + +for i in range(1, n): + if i == i2: + continue + + d = dist(p1, points[i]) + if d <= d_min and not aligned(p1, p2, points[i]): + d_min = d + p_min = i + +print(1, i2+1, p_min+1) \ No newline at end of file diff --git a/2024/03/25-03-24/d.py b/2024/03/25-03-24/d.py new file mode 100644 index 0000000..3cc96e9 --- /dev/null +++ b/2024/03/25-03-24/d.py @@ -0,0 +1,20 @@ +from math import ceil + +def main(): + x, y = [int(i) for i in input().split()] + + if x==y: + return x + + c = ceil(x / (2*y)) + if x < y: + return -1 + + if c > (x+y)/(2*x): + print(c, (x+y)/(2*x)) + c = ceil((x+y)/(2*x)) + + return (x+y)/(2*c) + + +print(main()) diff --git a/2024/04/08-04-24/a.py b/2024/04/08-04-24/a.py new file mode 100644 index 0000000..ee6263b --- /dev/null +++ b/2024/04/08-04-24/a.py @@ -0,0 +1,15 @@ +def main(): + n, d = map(int, input().split()) + a = [int(i) for i in input()] + + for c in range(len(a)): + i = a[c] + if i < d: + a.insert(c, d) + return "".join([str(b) for b in a]) + + return "".join([str(b) for b in a])+str(d) + + +for _ in range(int(input())): + print(main()) diff --git a/2024/04/08-04-24/b.py b/2024/04/08-04-24/b.py new file mode 100644 index 0000000..10da081 --- /dev/null +++ b/2024/04/08-04-24/b.py @@ -0,0 +1,30 @@ +def main(): + length = int(input()) + st = input() + + counts = [(0, 0) for i in range(len(st)+1)] + + found = set() + cur = 0 + for i in range(len(st)): + c = st[i] + if c not in found: + found.add(c) + cur += 1 + counts[i+1] = (cur, counts[i][1]) + + found = set() + cur = 0 + for i in range(len(st)-1, -1, -1): + c = st[i] + if c not in found: + found.add(c) + cur += 1 + counts[i] = (counts[i][0], cur) + + # print(counts) + return max([(c[0]+c[1]) for c in counts]) + + +for _ in range(int(input())): + print(main()) \ No newline at end of file diff --git a/2024/04/08-04-24/c.py b/2024/04/08-04-24/c.py new file mode 100644 index 0000000..15131c8 --- /dev/null +++ b/2024/04/08-04-24/c.py @@ -0,0 +1,8 @@ +def main(): + n = int(input()) + st = input() + + + +for _ in range(int(input())): + print(main()) \ No newline at end of file