QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#645176 | #9381. 502 Bad Gateway | False0099 | TL | 20ms | 11760kb | Python3 | 955b | 2024-10-16 17:09:16 | 2024-10-16 17:09:17 |
Judging History
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))
Details
Tip: Click on the bar to expand more detailed information
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...