kar7mp5

[Codeforces] Codeforces Round 951 (Div. 4) A, B, C, E 풀이 본문

Problem Solving/Codeforces

[Codeforces] Codeforces Round 951 (Div. 4) A, B, C, E 풀이

kar7mp5 2024. 6. 21. 23:49
728x90

https://codeforces.com/contest/1985/

A

import sys
input = sys.stdin.read
data = input().split()

t = int(data[0])
li = list(map(int, data[1:t + 1]))

results = []
for n in li:
    max_sum = 0
    optimal_x = 2
    for x in range(2, n + 1):
        k = n // x
        current_sum = x * k * (k + 1) // 2
        if current_sum > max_sum:
            max_sum = current_sum
            optimal_x = x
    results.append(optimal_x)

for result in results:
    print(result)

B

t = int(input())

for _ in range(t):
    a, b = input().split()
    x, y = a[0], a[2]
    a = b[0] + a[1] + a[2]
    b = x + b[1] + b[2]
    print(a, b)

C

import sys
input = sys.stdin.read

data = input().split()
t = int(data[0])
index = 1

results = []

for i in range(t):
    n = int(data[index])
    index += 1
    lst = set()
    SUM = 0
    cnt = 0

    for j in range(n):
        x = int(data[index])
        index += 1
        lst.add(x)
        SUM += x
        if SUM / 2 in lst:
            cnt += 1
    print(cnt)

E

import sys
input = sys.stdin.read

data = input().split()
t = int(data[0])
index = 1

results = []

for _ in range(t):
    x = int(data[index])
    y = int(data[index + 1])
    z = int(data[index + 2])
    k = int(data[index + 3])
    index += 4
    result = 0

    # 대충 x*y*z = k
    for a in range(1, int(k**(1/3))+2):
        if k % a == 0:
            for b in range(a, int((k // a)**(1/2)) + 2):
                if (k // a) % b == 0:
                    c = k // (a * b)
                    """
                    xyz
                    yxz
                    zyx

                    xzy
                    yzx
                    zxy
                    """
                    if a <= x and b <= y and c <= z:
                        tmp = (x - a + 1) * (y - b + 1) * (z - c + 1)
                        result = max(result, tmp)
                    if a <= y and b <= x and c <= z:
                        tmp = (y - a + 1) * (x - b + 1) * (z - c + 1)
                        result = max(result, tmp)
                    if a <= z and b <= y and c <= x:
                        tmp = (z - a + 1) * (y - b + 1) * (x - c + 1)
                        result = max(result, tmp)
                    if a <= x and b <= z and c <= y:
                        tmp = (x - a + 1) * (z - b + 1) * (y - c + 1)
                        result = max(result, tmp)
                    if a <= y and b <= z and c <= x:
                        tmp = (y - a + 1) * (z - b + 1) * (x - c + 1)
                        result = max(result, tmp)
                    if a <= z and b <= x and c <= y:
                        tmp = (z - a + 1) * (x - b + 1) * (y - c + 1)
                        result = max(result, tmp)

    print(result)
728x90