QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#645176#9381. 502 Bad GatewayFalse0099TL 20ms11760kbPython3955b2024-10-16 17:09:162024-10-16 17:09:17

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 17:09:17]
  • 评测
  • 测评结果:TL
  • 用时:20ms
  • 内存:11760kb
  • [2024-10-16 17:09:16]
  • 提交

answer

def compute_expected_penalty(T):
    import math
    from fractions import Fraction
    T = int(T)
    delta = int(math.isqrt(1 + 8 * T))
    while delta * delta < 1 + 8 * T:
        delta += 1
    k = (1 + delta) // 2
    while k * (k - 1) < 2 * T:
        k += 1
    if k == 1:
        E_refresh_num = 0
        E_refresh_den = 1
    else:
        N1 = k * k - 3 * k + 2 * T + 2
        D1 = 2 * (k - 1)
        E_refresh_num = N1
        E_refresh_den = D1

    S1_num = (k - 1) * k
    S1_den = 2

    S2 = T - k + 1

    E_total_num = S1_num * E_refresh_den + S1_den * S2 * (E_refresh_den + E_refresh_num)
    E_total_den = S1_den * E_refresh_den * T

    # Simplify fraction
    from math import gcd
    g = gcd(E_total_num, E_total_den)
    xi = E_total_num // g
    yi = E_total_den // g
    return f"{xi} {yi}"

n = int(input())
for _ in range(n):
    T = int(input())
    print(compute_expected_penalty(T))

详细

Test #1:

score: 100
Accepted
time: 20ms
memory: 11760kb

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: -100
Time Limit Exceeded

input:

1000000
1
1000000000
1
1
1000000000
1
1000000000
1
1
1
1000000000
1
1
1000000000
1
1000000000
1000000000
1
1000000000
1
1
1000000000
1
1000000000
1000000000
1
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
1
1
1000000000
1
1000000000
1000000000
1000000000
1000000000
1
1
1
10000000...

output:

1 1
1999961560 44721
1 1
1 1
1999961560 44721
1 1
1999961560 44721
1 1
1 1
1 1
1999961560 44721
1 1
1 1
1999961560 44721
1 1
1999961560 44721
1999961560 44721
1 1
1999961560 44721
1 1
1 1
1999961560 44721
1 1
1999961560 44721
1999961560 44721
1 1
1999961560 44721
1999961560 44721
1999961560 44721
19...

result: