QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#809590 | #9804. Guess the Polygon | OIer_kzc | WA | 6ms | 4080kb | C++20 | 5.6kb | 2024-12-11 16:09:34 | 2024-12-11 16:10:27 |
Judging History
answer
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
#define LOG(FMT...) fprintf(stderr, FMT)
#define fi first
#define se second
#define em emplace
#define eb emplace_back
using namespace std;
typedef long long LL;
constexpr int N = 1005, LB = 1, B = 1 << LB;
vector<int> operator + (const vector<int> &a, const vector<int> &b) {
vector<int> c(max(a.size(), b.size()));
int x = 0;
for (int i = 0; i < a.size() || i < b.size(); ++i) {
if (i < a.size()) x += a[i];
if (i < b.size()) x += b[i];
c[i] = x & B - 1;
x >>= LB;
}
if (x) {
c.eb(x);
}
return c;
}
bool operator < (const vector<int> &a, const vector<int> &b) {
if (a.size() != b.size()) {
return a.size() < b.size();
}
for (int i = (int)a.size() - 1; ~i; --i) {
if (a[i] != b[i]) {
return a[i] < b[i];
}
}
return false;
}
vector<int> operator - (vector<int> a, const vector<int> &b) {
if (a < b) {
LOG("ERR\n");
exit(0);
}
for (int i = 0; i < (int)a.size(); ++i) {
if (i < (int)b.size()) a[i] -= b[i];
if (a[i] < 0) {
a[i] += B;
a[i + 1] -= 1;
}
}
while (a.size() && !a.back()) {
a.pop_back();
}
return a;
}
vector<int> operator * (const vector<int> &a, const vector<int> &b) {
vector<int> c(a.size() + b.size() - 1, 0);
for (int i = 0; i < (int)a.size(); ++i) {
for (int j = 0; j < (int)b.size(); ++j) {
c[i + j] += a[i] * b[j];
}
}
int x = 0;
for (int i = 0; i < (int)c.size(); ++i) {
x += c[i];
c[i] = x & B - 1;
x >>= LB;
}
while (x) {
c.eb(x & B - 1);
x >>= LB;
}
return c;
}
void wr(const vector<int> &v) {
if (v.empty()) {
printf(" 0");
return;
}
LL t = 0;
for (int i = (int)v.size() - 1; ~i; --i) {
t = t << 1 | v[i];
}
printf(" %lld", t);
}
vector<int> operator / (vector<int> a, const vector<int> &b) {
if (a < b) {
LOG("ERR div\n");
exit(0);
}
if (b.empty() || b.back() == 0) {
LOG("ERR div b\n");
exit(0);
}
vector<int> ret((int)a.size() - (int)b.size() + 1, 0);
int x = 0;
while (a.size() >= b.size()) {
a.back() += 2 * x;
bool greater = true;
for (int j = 0; j < (int)b.size(); ++j) {
if (a[(int)a.size() - 1 - j] != b[(int)b.size() - 1 - j]) {
if (a[(int)a.size() - 1 - j] < b[(int)b.size() - 1 - j]) {
greater = false;
}
break;
}
}
if (greater) {
ret[(int)a.size() - (int)b.size()] = 1;
for (int j = 0; j < (int)b.size(); ++j) {
a[(int)a.size() - 1 - j] -= b[(int)b.size() - 1 - j];
if (a[(int)a.size() - 1 - j] < 0) {
a[(int)a.size() - 1 - j] += B;
a[(int)a.size() - j] -= 1;
}
}
}
x = a.back(), a.pop_back();
}
while (ret.size() && !ret.back()) {
ret.pop_back();
}
for (int x : a) {
if (x) {
LOG("ERR\n");
exit(0);
}
}
return ret;
}
vector<int> lshift(vector<int> a) {
if (a.empty()) {
return a;
}
for (int i = 1; i < (int)a.size(); ++i) {
a[i - 1] = a[i];
}
a.pop_back();
return a;
}
vector<int> rshift(vector<int> a) {
a.eb(0);
for (int i = (int)a.size() - 1; i; --i) {
a[i] = a[i - 1];
}
a[0] = 0;
return a;
}
vector<int> gcd(const vector<int> &a, const vector<int> &b) {
if (a.empty()) {
return b;
}
if (b.empty()) {
return a;
}
if (!(a[0] & 1) && !(b[0] & 1)) {
return rshift(gcd(lshift(a), lshift(b)));
}
if (!(a[0] & 1)) {
return gcd(lshift(a), b);
}
if (!(b[0] & 1)) {
return gcd(a, lshift(b));
}
return a < b ? gcd(a, b - a) : gcd(a - b, b);
}
void setv(vector<int> &v, LL t) {
v.clear();
LL x = t;
while (x) {
v.eb(x & B - 1);
x >>= LB;
}
}
LL gcd(LL x, LL y) {
return y ? gcd(y, x % y) : x;
}
pair<LL, LL> simp(LL a, LL b) {
if (a == 0ll) {
return {0ll, 1ll};
}
LL d = gcd(a, b);
a = a / d, b = b / d;
return {a, b};
}
pair<LL, LL> operator + (const pair<LL, LL> &s, const pair<LL, LL> &t) {
return simp(s.fi * t.se + s.se * t.fi, s.se * t.se);
}
pair<LL, LL> operator * (const pair<LL, LL> &s, int t) {
return simp(s.fi * t, s.se);
}
pair<LL, LL> operator / (const pair<LL, LL> &s, int t) {
return simp(s.fi, s.se * t);
}
struct Frac {
vector<int> x, y;
Frac() : x{}, y{1} {}
Frac(const vector<int> &_x, const vector<int> &_y) : x(_x), y(_y) {}
Frac simp(vector<int> a, vector<int> b) const {
vector<int> d = gcd(a, b);
a = a / d, b = b / d;
return Frac(a, b);
}
Frac(const pair<LL, LL> &t) {
setv(x, t.fi), setv(y, t.se);
}
Frac operator + (const Frac &t) const {
return simp(x * t.y + y * t.x, y * t.y);
}
void write() const {
printf("!");
wr(x), wr(y);
puts("");
fflush(stdout);
}
};
pair<LL, LL> Q(pair<LL, LL> t) {
printf("? %lld %lld\n", t.fi, t.se);
fflush(stdout);
pair<LL, LL> ret;
scanf("%lld%lld", &ret.fi, &ret.se);
return ret;
}
int n;
int xs[N], szd;
pair<LL, LL> v[N];
void solve1() {
for (int i = 1; i < n - 1; ++i) {
v[i] = Q(simp(xs[i], 1ll));
}
Frac res;
v[0] = v[n - 1] = {0ll, 1ll};
for (int i = 1; i < n; ++i) {
res = res + Frac((v[i] + v[i - 1]) * (xs[i] - xs[i - 1]) / 2);
}
res.write();
fflush(stdout);
}
void solve2() {
Frac res;
for (int i = 1; i < szd; ++i) {
res = res + Frac(Q(simp(xs[i] + xs[i - 1], 2ll)) * (xs[i] - xs[i - 1]));
}
res.write();
fflush(stdout);
}
int main() {
int task;
for (scanf("%d", &task); task--; ) {
scanf("%d", &n);
for (int i = 0, y; i < n; ++i) {
scanf("%d%d", xs + i, &y);
}
sort(xs, xs + n);
szd = unique(xs, xs + n) - xs;
if (szd == n) {
solve1();
} else {
solve2();
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4080kb
input:
2 4 3 0 1 3 1 1 0 0 1 1 1 1 3 0 0 999 1000 1000 999 1999 1000
output:
? 1 2 ? 2 1 ! 3 1 ? 999 1 ! 1999 2
result:
ok correct! (2 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 4068kb
input:
9 4 1 1 1 3 3 0 0 0 3 2 1 2 4 0 0 1 3 1 1 3 0 1 2 3 2 4 0 0 3 0 1 2 1 1 1 2 1 2 4 0 0 3 0 1 2 1 1 1 1 1 2 4 0 0 3 0 1 1 1 2 1 2 1 1 3 1000 0 0 0 0 1000 500 1 4 0 0 1000 0 1000 1000 0 1000 1000 1 5 0 1 1000 1000 1000 0 0 1000 1 0 1999 2 1000 1 9 4 1000 3 1 2 1000 3 1000 1 1 2 1 0 0 1 1000 4 0 500 1 1...
output:
? 1 2 ? 2 1 ! 5 2 ? 1 2 ? 2 1 ! 7 2 ? 1 2 ? 2 1 ! 3 2 ? 1 2 ? 2 1 ! 2 1 ? 1 2 ? 2 1 ! 5 2 ? 500 1 ! 500000 1 ? 500 1 ! 1000000 1 ? 1 2 ? 1001 2 ! 1999999 2 ? 1 2 ? 3 2 ? 5 2 ? 7 2 ! 4003 2
result:
ok correct! (9 test cases)
Test #3:
score: -100
Wrong Answer
time: 6ms
memory: 3816kb
input:
78 8 951 614 927 614 957 614 957 604 937 614 942 619 951 610 927 604 10 1 25 2 21 2 10 1 7 562 260 602 250 582 255 587 260 602 260 562 250 577 260 10 1 15 2 15 2 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 15 1 3 797 264 827 254 857 264 10 1 3 719 737 ...
output:
? 932 1 ? 1879 2 ? 1893 2 ? 954 1 ! 317 1 ? 1139 2 ? 1159 2 ? 1169 2 ? 1189 2 ! 375 1 ? 455 1 ! 585 1 ? 527 1 ! 585 1 ? 874 1 ! 600 1 ? 827 1 ! 300 1 ? 739 1 ! 600 1 ? 162 1 ! 400 1 ? 1489 2 ? 1499 2 ? 772 1 ! 275 1 ? 1869 2 ? 1879 2 ? 1889 2 ? 1899 2 ? 1909 2 ? 1919 2 ? 1929 2 ? 1939 2 ? 1949 2 ? 1...
result:
wrong answer format Unexpected end of file - token expected (test case 63)