QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#546561 | #7704. Plus Minus Four Squares | Olegpresnyakov# | WA | 15ms | 11540kb | Python3 | 1006b | 2024-09-04 09:21:01 | 2024-09-04 09:21:02 |
Judging History
answer
from fractions import Fraction
def check(n,s):
#print(n,s)
for i in range(len(s)):
if 2**(len(bin(n)) - 3) == n:
return False
if (s[i] == "E") != (n % 2 == 0):
return False
if n%2 == 0:
n //= 2
else:
n *= 3
n += 1
return True
s = input()
a,b = Fraction(1,1),Fraction(0,1)
for i in s[::-1]:
if i == "E":
a *= 2
b *= 2
if i == "O":
b -= 1
a /= 3
b /= 3
c = a.denominator
x,y = a.numerator, b.numerator * (b.denominator // c)
#print(x,y)
y %= c
x %= c
z = 1
good = False
r = 0
for _ in range(50):
#print(x,y,z,c)
if (x*z + y)%c == 0:
#print(x,y,z,c,r)
if check((a * (2**r) + b).numerator,s):
good = True
print((a * (2**r) + b).numerator)
break
z *= 2
z %= c
r += 1
if not good:
print("INVALID")
else:
r = (a * (2**r) + b).numerator
详细
Test #1:
score: 0
Wrong Answer
time: 15ms
memory: 11540kb
input:
64
output:
INVALID
result:
wrong answer 1st lines differ - expected: '12', found: 'INVALID'