QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#817648 | #9804. Guess the Polygon | cdd | WA | 1ms | 3776kb | C++23 | 3.2kb | 2024-12-17 09:36:36 | 2024-12-17 09:36:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef long long LL;
typedef unsigned long long uLL;
typedef __int128_t i128;
const int inf32 = 1e9;
const LL inf64 = 1e18;
i128 gcd(i128 a, i128 b) {
return !b ? a : gcd(b, a % b);
}
pii query(int p, int q) {
cout << "? " << p << ' ' << q << endl;
cin >> p >> q;
return make_pair(p, q);
}
void answer(int p, int q) {
cout << "! " << p << ' ' << q << endl;
}
pii operator + (pii a, pii b) {
auto &[x, y] = a;
auto &[p, q] = b;
// x / y + p / q;
i128 g = gcd(x, q);
if (g && x && q) x /= g, q /= g;
g = gcd(y, p);
if (g && y && p) y /= g, p /= g;
x = x * q + y * p;
y = y * q;
g = gcd(x, y);
if (g && x && y) x /= g, y /= g;
return a;
}
pii operator - (pii a, pii b) {
auto &[x, y] = a;
auto &[p, q] = b;
// x / y - p / q;
// cerr << x << ' ' << y << ' ' << p << ' ' << q << endl;
i128 g = gcd(x, q);
if (g && x && q) x /= g, q /= g;
// cerr << (LL)g << endl;
// cerr << x << ' ' << y << ' ' << p << ' ' << q << endl;
g = gcd(y, p);
if (g && y && p) y /= g, p /= g;
// cerr << (LL)g << endl;
// cerr << x << ' ' << y << ' ' << p << ' ' << q << endl;
x = x * q - y * p;
y = y * q;
// cerr << x << ' ' << y << ' ' << p << ' ' << q << endl;
g = gcd(x, y);
if (g && x && y) x /= g, y /= g;
return a;
}
pii operator * (pii a, int b) {
auto &[x, y] = a;
// x / y * b / 1;
i128 g = gcd(y, b);
if (y && b) y /= g, b /= g;
x = x * b;
return a;
}
pii operator / (pii a, int b) {
auto &[x, y] = a;
// x / y * 1 / b;
i128 g = gcd(x, b);
if (x && b) x /= g, b /= g;
y = y * b;
return a;
}
signed main()
{
cin.tie(0); cout.tie(0);
ios::sync_with_stdio(0);
int T = 1;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<pii> a(n + 5);
for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
sort(a.begin() + 1, a.begin() + 1 + n);
int lst_pos = -10000;
pii lst_len = {0, 1}, ans = {0, 1};
if (a[1].first == a[2].first && a[n].first == a[n - 1].first) {
lst_pos = a[1].first;
lst_len = query(a[1].first, 1);
} else if (a[1].first == a[2].first && a[n].first != a[n - 1].first) {
for (int i = 1; i <= n / 2; i++)
swap(a[i], a[n - i + 1]);
lst_len = {0, 1};
lst_pos = a[1].first;
} else {
lst_len = {0, 1};
lst_pos = a[1].first;
}
// for (int i = 1; i <= n; i++) cerr << a[i].first << ' ' << a[i].second << endl;
for (int i = 1; i <= n; i++) {
if (a[i].first == lst_pos) continue;
// cerr << i << endl;
pii new_len = i == n ? (pii){0, 1} : query(a[i].first, 1);
int len = abs(lst_pos - a[i].first);
ans = ans + ((new_len - lst_len) * len / 2);
ans = ans + lst_len * len;
lst_len = new_len;
lst_pos = a[i].first;
}
answer(ans.first, ans.second);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3564kb
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: 0ms
memory: 3776kb
input:
9 4 1 1 1 3 3 0 0 0 3 1
output:
? 1 1 ! 0 1
result:
wrong answer the answer is incorrect, expect: 5/2, find: 0/1 (test case 1)