QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#546561#7704. Plus Minus Four SquaresOlegpresnyakov#WA 15ms11540kbPython31006b2024-09-04 09:21:012024-09-04 09:21:02

Judging History

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

  • [2024-09-04 09:21:02]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:11540kb
  • [2024-09-04 09:21:01]
  • 提交

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'