QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#795054 | #9804. Guess the Polygon | ucup-team296# | WA | 3ms | 3696kb | C++20 | 3.4kb | 2024-11-30 17:40:02 | 2024-11-30 17:40:07 |
Judging History
answer
#include <bits/stdc++.h>
#define long long long int
#define DEBUG
using namespace std;
// @author: pashka
struct rat {
__int128_t p = 0, q = 1;
__int128_t mygcd(__int128_t a, __int128_t b) {
if (a < 0) a = -a;
if (b < 0) b = -b;
while (b != 0) {
__int128_t c = a % b;
a = b;
b = c;
}
return a;
}
rat(__int128_t _p, __int128_t _q) {
__int128_t d = mygcd(_p, _q);
p = _p / d;
q = _q / d;
if (q < 0) {
p = -p;
q = -q;
}
}
rat(long x) {
p = x;
}
rat() {
}
rat operator + (rat x) const {
return {p * x.q + x.p * q, q * x.q};
}
rat operator - (rat x) const {
return {p * x.q - x.p * q, q * x.q};
}
rat operator * (rat x) const {
return {p * x.p, q * x.q};
}
rat operator / (rat x) const {
return {p * x.q, q * x.p};
}
};
string tostring(__int128_t x) {
if (x == 0) return "0";
string s;
while (x > 0) {
s += (char)('0' + x % 10);
x /= 10;
}
reverse(s.begin(), s.end());
return s;
}
struct test {
rat ask(rat x) {
cout << "? " << tostring(x.p) << " " << tostring(x.q) << endl;
long p, q;
cin >> p >> q;
return {p, q};
}
rat calc(rat y1, rat y2, rat x1, rat x2, rat d) {
rat m = d * rat(1, 2);
rat r = y1 + ((m - x1) * (y2 - y1) / (x2 - x1));
return r * d;
}
void solve() {
int n;
cin >> n;
vector<int> x(n), y(n);
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
sort(x.begin(), x.end());
vector<pair<int, int>> xx;
for (int i = 0; i < n; i++) {
if (xx.empty() || x[i] > xx.back().first) {
xx.push_back({x[i], 1});
} else {
xx.back().second++;
}
}
int m = xx.size();
vector<rat> val(m, 0);
vector<rat> val2(m, 0);
for (int i = 0; i < m; i++) {
if (xx[i].second == 1) {
if (i > 0 && i < m - 1)
val[i] = ask(xx[i].first);
} else {
if (i > 0) {
val[i] = ask(rat(xx[i].first) - rat(1, 3));
}
if (i < m - 1) {
val2[i] = ask(rat(xx[i].first) + rat(1, 3));
}
}
}
rat res = 0;
for (int i = 0; i < m - 1; i++) {
rat x1, y1, x2, y2;
rat d = xx[i + 1].first - xx[i].first;
if (xx[i].second == 1) {
x1 = 0;
y1 = val[i];
} else {
x1 = {1, 3};
y1 = val2[i];
}
if (xx[i + 1].second == 1) {
x2 = d;
y2 = val[i + 1];
} else {
x2 = d - rat(1, 3);
y2 = val[i + 1];
}
res = res + calc(y1, y2, x1, x2, d);
}
// res = res * rat(1, 2);
cout << "! " << tostring(res.p) << " " << tostring(res.q) << endl;
}
};
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
test().solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3648kb
input:
2 4 3 0 1 3 1 1 0 0 4 3 5 3 3 0 0 999 1000 1000 999 1999 1000
output:
? 2 3 ? 4 3 ! 3 1 ? 999 1 ! 1999 2
result:
ok correct! (2 test cases)
Test #2:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
9 4 1 1 1 3 3 0 0 0 2 1 5 6 4 0 0 1 3 1 1 3 0 2 3 5 2 4 0 0 3 0 1 2 1 1 2 3 5 6 4 0 0 3 0 1 2 1 1 4 3 5 6 4 0 0 3 0 1 1 1 2 2 3 5 3 3 1000 0 0 0 0 1000 2999 3 4 0 0 1000 0 1000 1000 0 1000 1000 1 1000 1 5 0 1 1000 1000 1000 0 0 1000 1 0 2998 3 1000 1 1000 1 9 4 1000 3 1 2 1000 3 1000 1 1 2 1 0 0 1 1...
output:
? 2 3 ? 4 3 ! 5 2 ? 2 3 ? 4 3 ! 7 2 ? 2 3 ? 4 3 ! 3 2 ? 2 3 ? 4 3 ! 2 1 ? 2 3 ? 4 3 ! 5 2 ? 1 3 ! 500000 1 ? 1 3 ? 2999 3 ! 1000000 1 ? 1 3 ? 1 1 ? 2999 3 ! 1999999 2 ? 2 3 ? 4 3 ? 5 3 ? 7 3 ? 8 3 ? 10 3 ? 11 3 ! 4003 2
result:
ok correct! (9 test cases)
Test #3:
score: 0
Accepted
time: 3ms
memory: 3692kb
input:
78 8 951 614 927 614 957 614 957 604 937 614 942 619 951 610 927 604 10 1 10 1 15 1 19 3 10 1 10 1 7 562 260 602 250 582 255 587 260 602 260 562 250 577 260 10 1 10 1 5 1 10 1 10 1 3 454 98 494 68 455 68 117 4 3 526 589 566 559 527 559 117 4 3 854 496 854 466 894 466 119 4 3 797 264 827 254 857 264 ...
output:
? 2782 3 ? 937 1 ? 942 1 ? 2852 3 ? 2854 3 ? 2870 3 ! 317 1 ? 1687 3 ? 577 1 ? 582 1 ? 587 1 ? 1805 3 ! 375 1 ? 455 1 ! 585 1 ? 527 1 ! 585 1 ? 2563 3 ! 600 1 ? 827 1 ! 300 1 ? 2158 3 ! 600 1 ? 162 1 ! 400 1 ? 2227 3 ? 2240 3 ? 2242 3 ? 2255 3 ? 2257 3 ? 2375 3 ! 275 1 ? 2797 3 ? 2810 3 ? 2812 3 ? 2...
result:
ok correct! (78 test cases)
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3696kb
input:
34 24 123 815 168 800 133 795 27 827 153 805 28 830 178 780 138 810 78 830 192 772 148 790 88 810 43 825 183 795 103 805 163 785 118 800 93 825 63 835 73 815 58 820 198 790 48 840 108 820 10 3 95 6 15 2 95 6 15 2 95 6 15 2 95 6 15 2 95 6 15 2 95 6 15 2 95 6 15 2 95 6 15 2 95 6 15 2 95 6 15 2 15 1 24...
output:
? 28 1 ? 43 1 ? 48 1 ? 58 1 ? 63 1 ? 73 1 ? 78 1 ? 88 1 ? 93 1 ? 103 1 ? 108 1 ? 118 1 ? 123 1 ? 133 1 ? 138 1 ? 148 1 ? 153 1 ? 163 1 ? 168 1 ? 178 1 ? 183 1 ? 192 1 ! 1925 1 ? 54 1 ? 69 1 ? 74 1 ? 84 1 ? 89 1 ? 99 1 ? 104 1 ? 114 1 ? 119 1 ? 129 1 ? 134 1 ? 144 1 ? 149 1 ? 159 1 ? 164 1 ? 174 1 ? ...
result:
wrong answer format Expected integer, but "3431642152668165866303" found (test case 27)