QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#811282#9804. Guess the Polygonhos_lyricRE 0ms0kbD2.3kb2024-12-12 17:23:072024-12-12 17:23:08

Judging History

This is the latest submission verdict.

  • [2024-12-12 17:23:08]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-12-12 17:23:07]
  • Submitted

answer

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }

string COLOR(string s = "") { return "\x1b[" ~ s ~ "m"; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


real ask(long p, long q) {
  writefln("? %s %s", p, q);
  stdout.flush;
  const BigInt r = readToken;
  const BigInt s = readToken;
  return cast(real)(r) / cast(real)(s);
}

void main() {
  const numCases = readInt;
  foreach (caseId; 0 .. numCases) {
    const N = readInt;
    auto X = new long[N];
    auto Y = new long[N];
    foreach (u; 0 .. N) {
      X[u] = readLong;
      Y[u] = readLong;
    }
    
    const xs = X.dup.sort.uniq.array;
    const xsLen = cast(int)(xs.length);
    real ans = 0;
    if (xsLen == N) {
      auto ys = new real[xsLen];
      ys[0] = ys[xsLen - 1] = 0;
      foreach (i; 1 .. xsLen - 1) {
        ys[i] = ask(xs[i], 1);
      }
      foreach (i; 0 .. xsLen - 1) {
        ans += (xs[i + 1] - xs[i]) * (ys[i] + ys[i + 1]) / 2;
      }
    } else {
      foreach (i; 0 .. xsLen - 1) {
        const y = ask(xs[i] + xs[i + 1], 2);
        ans += (xs[i + 1] - xs[i]) * y;
      }
    }
    
    long p = cast(long)(round(ans));
    long q = 2;
    const g = gcd(p, q);
    p /= g;
    q /= g;
    writefln("! %s %s", p, q);
    stdout.flush;
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

2
4
3 0
1 3
1 1
0 0
1 1
1 1

output:

? 1 2
? 4 2
! 3 2

result: