QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#795207#9804. Guess the Polygonucup-team3734#TL 18ms11744kbPython31.2kb2024-11-30 18:37:382024-11-30 18:37:40

Judging History

This is the latest submission verdict.

  • [2024-11-30 18:37:40]
  • Judged
  • Verdict: TL
  • Time: 18ms
  • Memory: 11744kb
  • [2024-11-30 18:37:38]
  • Submitted

answer

import sys
from fractions import Fraction

def read_line():
    while True:
        line = sys.stdin.readline().strip()
        if len(line) > 0:
            return line
        

def assert_tl(cond: bool):
    if not cond:
        while True:
            pass

def assert_wa(cond: bool):
    if not cond:
        sys.exit(0)


def ask(x: Fraction):
    assert_tl(0 <= x <= 1000)
    assert_tl(0 <= x.denominator <= 1000)
    print('?', x.numerator, x.denominator, flush=True)
    p, q = map(int, read_line().split())
    assert_wa(q != 0)
    return Fraction(p, q)

def solve():
    n = int(read_line())

    pts = []
    for i in range(n):
        x, _ = map(int, read_line().split())
        assert_wa(0 <= x <= 1000)
        pts.append(Fraction(x, 1))

    pts = list(sorted(pts))
    answers = [Fraction(0) for _ in range(n)]
    for i in range(1, n - 1):
        answers[i] = ask(pts[i])
    S = Fraction(0)
    for i in range(0, n - 1):
        S += (pts[i + 1] - pts[i]) * (answers[i] + answers[i + 1])
    S /= 2
    print('!', S.numerator, S.denominator, flush=True)


if __name__ == "__main__":
    t = int(read_line())
    for _ in range(t):
        solve()

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 18ms
memory: 11744kb

input:

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

output:

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

result:

ok correct! (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

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

output:

? 1 1
? 1 1
! 9 2

result: