QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#626209 | #9434. Italian Cuisine | Dung1604 | WA | 18ms | 3620kb | C++17 | 4.6kb | 2024-10-10 00:28:21 | 2024-10-10 00:28:21 |
Judging History
answer
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <tuple>
#include <iomanip>
#include <map>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <unordered_map>
#define ll long long
#define inf 10000000000007
#define mod 1000000007
using namespace std;
const int BLOCK = 450;
ll fastpow(ll n, ll x) {
if (x == 0) {
return 1;
}
else {
ll ret = fastpow(n, x / 2);
ret = ((ret % mod) * (ret % mod)) % mod;
if (x % 2 == 0) {
return ret;
}
else {
return ((ret) * (n)) % mod;
}
}
}
ll gcd(ll a, ll b) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
else {
return gcd(b, a % b);
}
}
ll lcm(ll a, ll b) {
ll val = (a % mod * b % mod) % mod;
val = (val * fastpow(gcd(a, b), mod - 2)) % mod;
return val;
}
int Logk(ll n, ll k) {
if (k == 1) {
return 1;
}
if (n == 0) {
return 0;
}
int count = -1;
while (n > 0) {
count++;
n /= k;
}
return count;
}
struct Dsu {
vector<int> par;
void init(int n) {
par.resize(n + 5, 0);
for (int i = 1; i <= n; i++) par[i] = i;
}
int find(int u) {
if (par[u] == u) return u;
return par[u] = find(par[u]);
}
bool join(int u, int v) {
u = find(u); v = find(v);
if (u == v) return false;
par[v] = u;
return true;
}
} dsu;
struct point {
ll x, y;
};
struct line {
ll a, b, c;
};
struct vecto {
ll x, y;
};
line create(point point1, point point2) {
line ret;
ret.a = point2.y - point1.y;
ret.b = point1.x - point2.x;
ret.c = -(ret.a * point1.x + ret.b * point1.y);
return ret;
}
pair<ll, ll> dif(line line1, point point1) {
ll tu = abs(line1.a * point1.x + line1.b * point1.y + line1.c);
tu *= tu;
ll mau = line1.a * line1.a + line1.b * line1.b;
return { tu, mau };
}
int locate(point A, point B, point C) {
vecto AB = { B.x - A.x, B.y - A.y };
vecto AC = { C.x - A.x, C.y - A.y };
if (AB.x * AC.y - AB.y * AC.x < 0) {
return 2;
//RIGHT
}
else if (AB.x * AC.y - AB.y * AC.x > 0) {
return 1;
}
else {
return 0;
}
}
void solve() {
int n;
cin >> n;
ll x, y, r;
cin >> x >> y >> r;
vector<point> a;
vector<ll> prefix(n+1);
vector<ll> res(n, -1);
for (int i = 0; i < n; i++) {
ll x, y;
cin >> x >> y;
a.push_back({ x, y });
}
a.push_back(a[0]);
prefix[0] = 0;
for (int i = 1; i <= n; i++) {
prefix[i] = prefix[i-1] + (a[i-1].x * a[i].y - a[i-1].y * a[i].x);
}
prefix[n] = abs(prefix[n]);
ll ans = 0;
int cur = 0;
int nxt = 2;
while (1) {
point first = a[cur];
res[cur] = 0;
point last = a[nxt];
pair<ll, ll> dis = dif(create(first, last), { x, y });
if (dis.first <= r * r * dis.second) {
cur++;
cur %= n;
if (abs(nxt - cur) <= 1) {
nxt = cur + 2;
nxt %= n;
}
if (res[cur] != -1) {
break;
}
}
else {
if (first.y <= last.y) {
int type = locate(first, last, { x, y });
if (type == 1) {
if (cur < nxt) {
ans = max(ans, prefix[nxt] - prefix[cur] + (a[nxt].x * a[cur].y - a[nxt].y * a[cur].x));
}
else {
ans = max(ans, prefix[n] - (prefix[cur] - prefix[nxt] + (a[cur].x * a[nxt].y - a[cur].y * a[nxt].x)));
}
nxt++;
nxt %= n;
if (abs(nxt - cur) <= 1) {
nxt = cur - 2;
}
}
else {
cur++;
cur %= n;
if (abs(nxt - cur) <= 1) {
nxt = cur + 2;
nxt %= n;
}
if (res[cur] != -1) {
break;
}
}
}
else {
int type = locate(first, last, { x, y });
if (type == 1) {
if (cur < nxt) {
ans = max(ans, prefix[nxt] - prefix[cur] + (a[nxt].x * a[cur].y - a[nxt].y * a[cur].x));
}
else {
ans = max(ans, prefix[n] - (prefix[cur] - prefix[nxt] + (a[cur].x * a[nxt].y - a[cur].y * a[nxt].x)));
}
nxt++;
nxt %= n;
if (abs(nxt - cur) <= 1) {
nxt = cur - 2;
nxt %= n;
}
}
else {
cur++;
cur %= n;
if (abs(nxt - cur) <= 1) {
nxt = cur + 2;
nxt %= n;
}
if (res[cur] != -1) {
break;
}
}
}
}
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
3 5 1 1 1 0 0 1 0 5 0 3 3 0 5 6 2 4 1 2 0 4 0 6 3 4 6 2 6 0 3 4 3 3 1 3 0 6 3 3 6 0 3
output:
5 24 0
result:
ok 3 number(s): "5 24 0"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
1 6 0 0 499999993 197878055 -535013568 696616963 -535013568 696616963 40162440 696616963 499999993 -499999993 499999993 -499999993 -535013568
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 18ms
memory: 3552kb
input:
6666 19 -142 -128 26 -172 -74 -188 -86 -199 -157 -200 -172 -199 -186 -195 -200 -175 -197 -161 -188 -144 -177 -127 -162 -107 -144 -90 -126 -87 -116 -86 -104 -89 -97 -108 -86 -125 -80 -142 -74 -162 -72 16 -161 -161 17 -165 -190 -157 -196 -154 -197 -144 -200 -132 -200 -128 -191 -120 -172 -123 -163 -138...
output:
5093 2862 2539 668 3535 7421 4883 5711 5624 1034 2479 3920 4372 2044 4996 5070 2251 4382 4175 1489 1154 3231 4038 1631 5086 14444 1692 6066 687 1512 4849 5456 2757 8341 8557 8235 1013 5203 10853 6042 6300 4480 2303 2728 1739 2187 3385 4266 6322 909 4334 1518 948 5036 1449 2376 3180 4810 1443 1786 47...
result:
wrong answer 2nd numbers differ - expected: '3086', found: '2862'