QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#706216 | #8067. Scientific Grading | jerry2423 | WA | 15ms | 10860kb | Python3 | 1.9kb | 2024-11-03 09:25:10 | 2024-11-03 09:25:10 |
Judging History
answer
import math
import sys
billion = 1_000_000_000
def normalize(xs, xe):
if xs == 0:
return 0, 0
correction = int(math.ceil(math.log(billion / abs(xs), 10)))
xs *= 10 ** correction
xe -= correction
return int(xs), xe
def align(xs, xe, ys, ye):
if xe >= ye:
if xe - ye <= 9:
delta = xe - ye
ys //= 10 ** delta
ye += delta
else:
if ye - xe <= 9:
delta = ye - xe
xs //= 10 ** delta
xe += delta
return xs, xe, ys, ye
def add(xs, xe, ys, ye):
xs, xe, ys, ye = align(xs, xe, ys, ye)
zs = xs + ys
ze = 0 if zs == 0 else xe
return normalize(zs, ze)
def sub(xs, xe, ys, ye):
xs, xe, ys, ye = align(xs, xe, ys, ye)
zs = xs - ys
ze = 0 if zs == 0 else xe
return normalize(zs, ze)
def mul(xs, xe, ys, ye):
zs = int(round(xs * ys / billion))
ze = xe + ye
return normalize(zs, ze)
def div(xs, xe, ys, ye):
zs = int(round(((xs * billion * 10) / ys)))
ze = xe - ye - 1
return normalize(zs, ze)
def process(string):
s, e = string.split("e")
s = int(float(s) * billion)
e = int(e)
return s, e
xs, xe = process(input().strip())
ys, ye = process(input().strip())
#print(xs, xe)
#print(ys, ye)
#print(*div(xs, xe, ys, ye))
#sys.exit(0)
x = (xs, xe)
y = (ys, ye)
ans = [add(*x, *y), sub(*x, *y), mul(*x, *y), div(*x, *y)]
for zts, zte in ans:
zs, ze = process(input().strip())
# print("given ", zs, ze)
# print("expected", zts, zte)
correct = True
error1 = sub(zs, ze, zts, zte)
error1 = abs(error1[0]), error1[1]
correct = correct and (error1 == (0, 0) or error1[1] < -9)
#print("error1:", *error1)
#if error1 != (0, 0):
error2 = div(*error1, abs(zs), ze)
correct = correct and (error2 == (0, 0) or error2[1] < -9)
#print("error2:", *error2)
if zts == zs and zte == ze:
print("Correct")
else:
print("Incorrect")
详细
Test #1:
score: 100
Accepted
time: 15ms
memory: 10848kb
input:
+2.000000000e+1 +3.000000000e+2 +3.200000000e+2 -2.800000000e+2 +6.000000000e+3 +6.666666667e-2
output:
Correct Correct Correct Correct
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 14ms
memory: 10860kb
input:
+1.000000000e-1 +1.000000000e-1 +2.000000003e-1 +1.000000000e-18 +1.000000002e-2 +1.000000001e+0
output:
Incorrect Incorrect Incorrect Incorrect
result:
ok 4 lines
Test #3:
score: -100
Wrong Answer
time: 15ms
memory: 10832kb
input:
+9.999999999e+400000000 +1.000000000e-400000009 +9.999999999e+400000000 +9.999999999e+400000000 +9.999999999e-9 +9.999999999e+800000009
output:
Incorrect Incorrect Correct Correct
result:
wrong answer 1st lines differ - expected: 'Correct', found: 'Incorrect'