QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#618270 | #9417. Palindromic Polygon | supepapupu# | WA | 1ms | 3632kb | C++20 | 2.2kb | 2024-10-06 20:19:06 | 2024-10-06 20:19:11 |
Judging History
answer
#include <bits/stdc++.h>
#define x first
#define y second
#define el '\n'
#define debug(x) cerr << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 3e5 + 10, mod = 998244353;
const ll INF = 4e18;
pii operator-(const pii &a, const pii &b) {
return {a.x - b.x, a.y - b.y};
}
ll operator^(const pii &a, const pii &b) {
return (ll)a.x * b.y - (ll)a.y * b.x;
}
ll area(const pii &a, const pii &b, const pii &c) {
return abs((b - a) ^ (c - a));
}
__int128 sq(ll x) {
return (__int128)x * x;
}
void solve() {
int n; cin >> n;
// int n = 500;
vector<int> s(n);
vector<pii> q(n);
for (int i = 0; i < n; ++i) cin >> s[i], s.emplace_back(s[i]);
for (int i = 0; i < n; ++i) {
cin >> q[i].x >> q[i].y;
q.emplace_back(q[i]);
}
vector<vector<int>> match(n, vector<int>(n)), match2(n, vector<int>(n));
for (int i = 0; i < n; ++i) {
match[i][i] = match2[i][i] = i;
for (int j = i + 1; j < n * 2; ++j) {
match[i][j % n] = match[i][(j - 1) % n];
if (s[i] == s[j]) match[i][j % n] = j % n;
}
for (int j = i - 1; j >= 0; --j) {
match2[i][j % n] = match2[i][(j + 1) % n];
if (s[i] == s[j]) match2[i][j % n] = j % n;
}
}
vector<vector<ll>> f(n, vector<ll>(n));
ll ans = 0;
for (int len = 1; len < n; ++len) {
for (int i = 0; i < n; ++i) {
int j = (i + len) % n;
int jj = (i + len - 1) % n;
int ii = (i + 1) % n;
if (s[i] != s[j]) continue;
for (int k = ii; k != j; k = k + 1 >= n ? k + 1 - n : k + 1) {
ll t = area(q[j], q[i], q[k]);
f[i][j] = max(f[i][j], t + area(q[j], q[k], q[match[k][jj]]) + f[k][match[k][jj]]);
f[i][j] = max(f[i][j], t + area(q[i], q[match2[k][ii]], q[k]) + f[match2[k][ii]][k]);
}
ans = max(ans, f[i][j]);
}
}
cout << ans << el;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int tcase = 1;
cin >> tcase;
while (tcase--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
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: 3600kb
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: 3632kb
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:
3857 1068 922 516 2668 3559 1165 3468 560 925 3502 696 3824 1746 2970 1987 1052 2221 1130 4677 1900 1646 564 273 3203 6572 1275 3330 1296 765 142 3038 1615 9445 2122 320 1741 2561 1146 480 2094 5119 5590 2446 3929 2249 4378 4927 2304 1473 3506 1574 1990 1609 3367 2088 1459 2663 2617 2422 4048 215 54...
result:
wrong answer 3rd numbers differ - expected: '877', found: '922'