QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#797469#9804. Guess the PolygonsnowysecretWA 6ms9924kbC++142.9kb2024-12-03 04:06:142024-12-03 04:06:15

Judging History

This is the latest submission verdict.

  • [2024-12-03 04:06:15]
  • Judged
  • Verdict: WA
  • Time: 6ms
  • Memory: 9924kb
  • [2024-12-03 04:06:14]
  • Submitted

answer

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
const int MAXN = 4e5 + 10, MOD = 1e9 + 7, HASHMOD = 1734232211;
int fac[MAXN], invfac[MAXN];
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) { return uniform_int_distribution<int>(x, y)(rng); }
int bm(int b, int p) {
  if(p==0) return 1 % MOD;
  int r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
int inv(int b) { return bm(b, MOD-2); }
vector<int> prefix_function(vector<int> t) {
  int n = t.size(); vector<int> lps(n, 0);
  for(int i=1; i<n; i++) {
    int j = lps[i-1]; while(j > 0 && t[i] != t[j]) j = lps[j-1];
    lps[i] = (t[i] == t[j] ? j+1 : 0); 
  } return lps;
}
int nCr(int n, int r) {
  return (((fac[n] * invfac[r]) % MOD) * invfac[n-r]) % MOD;
}
void precomp() {
  for(int i=0; i<MAXN; i++) fac[i] = (i ? (fac[i-1] * i) % MOD : 1);
  invfac[MAXN - 1] = inv(fac[MAXN - 1]);
  for(int i=MAXN-2; i>=0; i--) invfac[i] = (invfac[i+1] * (i+1)) % MOD;
}
struct Fraction {
  __int128 gcdd(__int128 x, __int128 y) {
    if(x == 0) return y;
    if(y == 0) return x;
    if(x < y) return gcdd(x, y % x);
    return gcdd(y, x % y);
  }
  int p, q;
  Fraction operator*(Fraction other) {
    __int128 num = p, den = q;
    num *= other.p, den *= other.q;
    __int128 g = gcdd(num, den);
    num /= g, den /= g;
    int n1 = num, n2 = den;
    Fraction product = {n1, n2};
    return product;
  }
  Fraction operator+(Fraction other) {
    __int128 l = q * other.q / gcdd(q, other.q); 
    __int128 num = p * l/q + other.p * l/other.q;
    __int128 g = gcdd(l, num);
    l /= g, num /= g;
    int n1 = num, n2 = l;
    Fraction sum = {n1, n2};
    return sum;
  }
};
Fraction frac(int p, int q) {
  return {p, q};
}
void solve(int tc) {
  int n;
  cin >> n;
  pair<int, int> p[n+1];
  for(int i=1; i<=n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p + 1, p + n + 1);
  vector<pair<int, Fraction>> v;
  if(p[1].first != p[2].first) {
    v.push_back({p[1].first, {0, 1}});
  }
  for(int i=2; i<=n-1; i++) {
    if(p[i].first == p[i-1].first && i > 2) continue;
    cout << "? " << p[i].first << " 1" << endl;
    int pp, q;
    cin >> pp >> q;
    v.push_back({p[i].first, {pp, q}});
  }
  if(p[n-1].first != p[n].first) {
    v.push_back({p[n].first, {0, 1}});
  }
  Fraction ans = {0, 1};
  for(int i=1; i<v.size(); i++) {
    Fraction base = v[i-1].second + v[i].second;
    int height = v[i].first - v[i-1].first;
    Fraction res1 = base * frac(height, 2);
    ans = ans + res1;
  }
  cout << "! " << ans.p << " " << ans.q << endl;


  


}
int32_t main() {
  precomp();
  //ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
/*
g++ code.cpp -std=c++17 -O2 -o code
./code < input.txt
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 9924kb

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
Wrong Answer
time: 6ms
memory: 9880kb

input:

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

output:

? 1 1
! 9 2

result:

wrong answer the answer is incorrect, expect: 5/2, find: 9/2 (test case 1)