QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#598898 | #9417. Palindromic Polygon | ucup-team3584# | WA | 1ms | 3652kb | C++23 | 4.6kb | 2024-09-28 23:57:25 | 2024-09-28 23:57:25 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }
// 整数幾何
typedef ll Integer;
const Integer eps = 0;
inline constexpr int arg_type(Integer x, Integer y) { return y < 0 ? 2 : x < 0 ? 1 : 0; }
struct Point {
Integer x, y;
constexpr explicit Point(Integer x = 0, Integer y = 0) : x(x), y(y) {}
constexpr Point operator+() const noexcept { return *this; }
constexpr Point operator-() const noexcept { return Point(-x, -y); }
constexpr Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); }
constexpr Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }
constexpr Point &operator+=(const Point &p) { return x += p.x, y += p.y, *this; }
constexpr Point &operator-=(const Point &p) { return x -= p.x, y -= p.y, *this; }
constexpr Point &operator*=(const Integer &k) { return x *= k, y *= k, *this; }
constexpr Point operator*(const Integer &k) const { return Point(x * k, y * k); }
constexpr bool operator==(const Point &r) const noexcept { return r.x == x and r.y == y; }
constexpr Integer dot(const Point &r) const { return x * r.x + y * r.y; }
constexpr Integer cross(const Point &r) const { return x * r.y - y * r.x; }
constexpr Integer norm2() const { return x * x + y * y; }
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int q;
cin >> q;
auto area = [&](Point a, Point b, Point c) -> ll {
b -= a, c -= a;
ll bx = b.x, by = b.y, cx = c.x, cy = c.y;
return abs(bx * cy - cx * by);
};
while (q--) {
int n, m;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
vector<Point> p(n);
for (int i = 0; i < n; ++i) {
cin >> p[i].x >> p[i].y;
}
vector<vector<int>> nxt_r(n), nxt_l(n);
{
auto z = v;
sort(z.begin(), z.end());
z.erase(unique(z.begin(), z.end()), z.end());
m = z.size();
for (int i = 0; i < n; ++i) {
nxt_l[i].resize(m), nxt_r[i].resize(m);
v[i] = lower_bound(z.begin(), z.end(), v[i]) - z.begin();
}
for (int i = 0; i < n; ++i) {
nxt_l[i][v[i]] = nxt_r[i][v[i]] = i;
for (int j = 0, k = i; j < n; ++j) {
k -= 1;
if (k == -1) k = n - 1;
if (v[k] == v[i]) break;
nxt_r[k][v[i]] = i;
}
for (int j = 0, k = i; j < n; ++j) {
k += 1;
if (k == n) k = 0;
if (v[k] == v[i]) break;
nxt_l[k][v[i]] = i;
}
}
}
ll res = 0;
vector<vector<ll>> dp(n, vector<ll>(n, -1));
for (int i = 0; i < n; ++i) {
dp[i][i] = 0;
}
auto valid = [&](int l, int r, int x) -> bool {
if (l <= r) {
if (l <= x and x < r) return false;
else return true;
} else {
if (r <= x and x < l) return true;
else return false;
}
};
auto calc = [&](auto calc, int l, int r) -> ll {
if (dp[l][r] != -1) return dp[l][r];
dp[l][r] = 0;
for (int i = 0, j = l; i < n; ++i) {
if (j == r) break;
int k = nxt_r[r][v[j]];
if (valid(j, r, k)) {
dp[l][r] = max(dp[l][r], calc(calc, j, k) + area(p[l], p[r], p[j]) + area(p[j], p[k], p[r]));
}
j -= 1;
if (j == -1) j = n - 1;
}
return dp[l][r];
};
for (int i = 0; i < n; ++i) {
for (int j = 0, k = i; j < n; ++j) {
k += 1;
if (k == n) k = 0;
if (v[i] == v[k] and dp[i][k] == -1) {
calc(calc, i, k);
}
res = max(res, dp[i][k]);
for (int l = 0, kk = i; l < j; ++l) {
kk += 1;
if (kk == n) kk = 0;
res = max(res, dp[i][k] + area(p[i], p[kk], p[k]));
}
}
}
cout << res << "\n";
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
input:
3 8 2 4 2 4 3 4 5 3 2 3 0 6 -3 3 -3 0 -2 -3 1 -5 3 -3 4 0 3 1 2 3 0 0 1 0 0 1 3 1 1 1 0 0 1 0 0 1
output:
84 0 1
result:
ok 3 number(s): "84 0 1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
1 4 1000000000 1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 -1000000000 1000000000 1000000000 -1000000000 1000000000
output:
8000000000000000000
result:
ok 1 number(s): "8000000000000000000"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3628kb
input:
129 10 604040473 604040473 287094217 682965575 70435786 287094217 604040473 287094217 682965575 92620053 -193 -184 -200 -200 -125 -169 -120 -157 -120 -145 -124 -139 -137 -136 -155 -149 -172 -163 -187 -177 5 346787871 346787871 113397429 113397429 346787871 -173 -181 -186 -166 -200 -195 -194 -200 -17...
output:
3938 1068 1239 516 2668 3559 1165 3637 560 925 3502 708 3824 1746 2970 1987 1011 2221 1245 4762 1900 1646 564 273 3203 6572 1070 3378 1024 799 142 3104 1883 9445 2128 395 1741 2657 1276 480 2107 5119 5458 2446 4031 2249 4378 5192 2226 1473 3152 1770 2160 1655 3367 2298 1459 2663 2617 2447 4239 232 5...
result:
wrong answer 1st numbers differ - expected: '3857', found: '3938'