QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#449929 | #8294. Axis of Symmetry | PetroTarnavskyi# | WA | 0ms | 3784kb | C++20 | 3.0kb | 2024-06-21 19:39:33 | 2024-06-21 19:39:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int mod1 = 1e9 + 7;
const int mod2 = 1e9 + 9;
const LL mod = (LL)mod1 * mod2;
const int C = 2e8 + 47;
const int INF = 1e9;
const LL p = 892388953;
const LL q = 347723788;
LL add(LL a, LL b)
{
return a + b < mod ? a + b : a + b - mod;
}
LL sub(LL a, LL b)
{
return a - b >= 0 ? a - b : a - b + mod;
}
LL mult(LL a, LL b)
{
return (__int128)a * b % mod;
}
LL binpow(LL a, int n)
{
LL res = 1;
while (n)
{
if (n & 1)
res = mult(res, a);
a = mult(a, a);
n >>= 1;
}
return res;
}
LL getRectHash(int x1, int y1, int x2, int y2)
{
if (x1 > x2)
swap(x1, x2);
if (y1 > y2)
swap(y1, y2);
return mult(sub(binpow(p, x2 + C), binpow(p, x1 + C)), sub(binpow(q, y2 + C), binpow(q, y1 + C)));
}
pair<bool, PII> reflect(LL a, LL b, LL c, LL x, LL y)
{
LL num1 = 2 * a * (a * x + b * y + c), num2 = 2 * b * (a * x + b * y + c);
LL den = a * a + b * b;
if (num1 % den != 0 || num2 % den != 0)
{
return {false, {0, 0}};
}
return {true, {x - num1 / den, y - num2 / den}};
}
void solve()
{
int n;
cin >> n;
VI x1(n), y1(n), x2(n), y2(n);
FOR(i, 0, n)
{
cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
}
LL h0 = 0;
FOR(i, 0, n)
{
h0 = add(h0, getRectHash(x1[i], y1[i], x2[i], y2[i]));
}
auto check = [&](int a, int b, int c) -> bool
{
LL h = 0;
FOR(i, 0, n)
{
auto [can1, p1] = reflect(a, b, c, x1[i], y1[i]);
auto [can2, p2] = reflect(a, b, c, x2[i], y2[i]);
if (!can1 || !can2)
return false;
h = add(h, getRectHash(p1.F, p1.S, p2.F, p2.S));
}
return h == h0;
};
vector<tuple<int, int, int>> ans;
auto f = [&](int a, int b) -> void
{
int mn = INF, mx = -INF;
FOR(i, 0, n)
{
mn = min(mn, a * x1[i] + b * y1[i]);
mn = min(mn, a * x1[i] + b * y2[i]);
mn = min(mn, a * x2[i] + b * y1[i]);
mn = min(mn, a * x2[i] + b * y2[i]);
mx = max(mx, a * x1[i] + b * y1[i]);
mx = max(mx, a * x1[i] + b * y2[i]);
mx = max(mx, a * x2[i] + b * y1[i]);
mx = max(mx, a * x2[i] + b * y2[i]);
}
int c = -(mn + mx) / 2;
if (check(a, b, c))
{
ans.PB({a, b, c});
}
};
f(0, 2);
f(2, 0);
f(2, 2);
f(2, -2);
for (auto& [a, b, c] : ans)
{
int g = gcd(gcd(abs(a), abs(b)), abs(c));
a /= g;
b /= g;
c /= g;
}
sort(ALL(ans), greater());
cout << SZ(ans) << "\n";
FOR(i, 0, SZ(ans))
{
auto [a, b, c] = ans[i];
if (i > 0)
cout << " ";
cout << a << " " << b << " " << c;
}
cout << "\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
3 2 -1 -1 0 1 0 0 1 2 2 -1 -1 0 0 0 0 1 1 3 -1 -1 0 1 0 -1 1 0 0 0 1 1
output:
0 2 1 1 0 1 -1 0 4 1 1 0 1 0 0 1 -1 0 0 1 0
result:
ok 6 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3784kb
input:
1 1 0 0 1 1
output:
4 2 0 -1 1 1 -1 1 -1 0 0 2 -1
result:
wrong answer 2nd lines differ - expected: '2 0 1 1 1 1 1 -1 0 0 2 1', found: '2 0 -1 1 1 -1 1 -1 0 0 2 -1'