QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#799003#9804. Guess the PolygonqlwpcRE 13ms11792kbPython3976b2024-12-04 20:18:142024-12-04 20:18:14

Judging History

This is the latest submission verdict.

  • [2024-12-04 20:18:14]
  • Judged
  • Verdict: RE
  • Time: 13ms
  • Memory: 11792kb
  • [2024-12-04 20:18:14]
  • Submitted

answer

import fractions
import sys

def query(x : int):
    print(f"? {x} 1")
    sys.stdout.flush()
    r, s = tuple(map(int, input().split()))
    return fractions.Fraction(r, s)

T=int(input())
while T>0:
    T-=1
    n=int(input())
    A = [tuple(map(int,input().split())) for _ in range(n)]
    A.sort()
    lstlen = fractions.Fraction(0, 1)
    ans = fractions.Fraction(0, 1)
    lstx = A[0][0]
    ton = [0 for _ in range(1001)]
    mx = 0
    for x,y in A:
        ton[x]+=1
        mx = max(mx, x)
    for i in range(n):
        if i!=0 and A[i][0]==A[i-1][0]:
            continue
        x = A[i][0]
        if x==mx and ton[x]==1:
            ans = ans + lstlen*(x-lstx)*fractions.Fraction(1,2)
        elif ton[x]>1 or i>0:
            len = query(x)
            ans = ans + (lstlen+len)*(x-lstx)*fractions.Fraction(1,2)
            lstlen=len
        lstx = x
    print(f"! {ans.numerator} {ans.denominator}")
    sys.stdout.flush()

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 13ms
memory: 11792kb

input:

2
4
3 0
1 3
1 1
0 0
2 1
3
0 0
999 1000
1000 999
1999 1000

output:

? 1 1
! 3 1
? 999 1
! 1999 2

result:

ok correct! (2 test cases)

Test #2:

score: -100
Dangerous Syscalls

input:

9
4
1 1
1 3
3 0
0 0
3 1

output:

? 1 1
! 9 2

result: