QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#603373 | #9417. Palindromic Polygon | Capps | WA | 1ms | 3756kb | C++20 | 4.8kb | 2024-10-01 16:14:20 | 2024-10-01 16:14:22 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
template <class T, class G>
struct BaseVector2 {
T x, y;
constexpr BaseVector2() : BaseVector2(T{}, T{}) {}
constexpr BaseVector2(T x, T y) : x{x}, y{y} {}
// 运算
constexpr BaseVector2 operator+(BaseVector2 a) const {
return BaseVector2(x + a.x, y + a.y);
}
constexpr BaseVector2 operator-(BaseVector2 a) const {
return BaseVector2(x - a.x, y - a.y);
}
constexpr BaseVector2 operator-() const {
return BaseVector2(-x, -y);
}
constexpr G operator*(BaseVector2 a) const {
return G(x) * a.x + G(y) * a.y;
}
constexpr G operator%(BaseVector2 a) const {
return G(x) * a.y - G(y) * a.x;
}
constexpr BaseVector2 rotate() const {
return BaseVector2(-y, x);
}
template <class Float>
constexpr BaseVector2 rotate(Float theta) const {
BaseVector2 b(cosl(theta), sinl(theta));
return BaseVector2(x * b.x - y * b.y,
x * b.y + y * b.x);
}
constexpr friend BaseVector2 operator*(const T &a, BaseVector2 b) {
return BaseVector2(a * b.x, a * b.y);
}
// 比较
constexpr bool operator<(BaseVector2 a) const {
if (x == a.x) {
return y < a.y;
}
return x < a.x;
}
constexpr bool operator>(BaseVector2 a) const {
if (x == a.x) {
return y > a.y;
}
return x > a.x;
}
constexpr bool operator<=(BaseVector2 a) const {
if (x == a.x) {
return y <= a.y;
}
return x <= a.x;
}
constexpr bool operator>=(BaseVector2 a) const {
if (x == a.x) {
return y >= a.y;
}
return x >= a.x;
}
constexpr bool operator==(BaseVector2 a) const {
return x == a.x and y == a.y;
}
constexpr bool operator!=(BaseVector2 a) const {
return x != a.x or y != a.y;
}
// 输入输出
friend std::istream &operator>>(std::istream &in, BaseVector2 &p) {
return in >> p.x >> p.y;
}
friend std::ostream &operator<<(std::ostream &ot, BaseVector2 p) {
return ot << '(' << p.x << ", " << p.y << ')';
}
};
template <class T, class G>
G dis2(BaseVector2<T, G> a, BaseVector2<T, G> b = BaseVector2<T, G>(0, 0)) {
BaseVector2<T, G> p = a - b;
return p * p;
}
template <class T, class G>
auto dis(BaseVector2<T, G> a, BaseVector2<T, G> b = BaseVector2<T, G>(0, 0)) {
return sqrtl(dis2(a, b));
}
template <class T, class G>
int sgn(BaseVector2<T, G> p) {
if (p.x < 0 or p.x == 0 and p.y > 0) {
return 1;
} else
return 0;
// 以41象限为先
}
template <class Vector>
bool polarCmp(Vector p, Vector q) {
if (sgn(p) == sgn(q)) {
if (p % q == 0) {
return dis2(p) < dis2(q);
} else {
return p % q > 0;
}
} else {
return sgn(p) < sgn(q);
}
}
using Point = BaseVector2<int, i64>;
using Vector = Point;
using PS = std::vector<Point>;
void solve() {
int n;
std::cin >> n;
std::vector<int> w(n * 2);
for (int i = 0; i < n; i++) {
std::cin >> w[i];
w[i + n] = w[i];
}
PS ps(n * 2);
for (int i = 0; i < n; i++) {
std::cin >> ps[i];
ps[i + n] = ps[i];
}
constexpr i64 Inf = ((1LL << 62) - 1) * 2;
std::vector f(n * 2, std::vector(n * 2, std::array<i64, 3>{-Inf, -Inf, -Inf}));
for (int i = 0; i < n * 2; i++) {
f[i][i][0] = 0;
int j = i + 1;
if (j < n * 2) {
if (w[i] == w[j]) {
f[i][j] = {0, 0, 0};
} else {
f[i][j] = {-Inf, 0, 0};
}
}
}
i64 ans = 0;
for (int len = 3; len <= n; len++) {
for (int l = 0; l < n * 2; l++) {
int r = l + len - 1;
if (r >= n * 2) {
continue;
}
for (int k = l + 1; k < r; k++) {
i64 S = ps[l] % ps[k] + ps[k] % ps[r] + ps[r] % ps[l];
if (w[l] == w[r]) {
f[l][r][0] = std::max({f[l][r][0], f[l][k][1] + S, f[k][r][2] + S});
}
if (w[l] == w[k]) {
f[l][r][2] = std::max(f[l][r][2], f[l][k][0] + S);
}
if (w[r] == w[k]) {
f[l][r][1] = std::max(f[l][r][1], f[k][r][0] + S);
}
}
ans = std::max(ans, f[l][r][0]);
}
}
std::cout << ans << '\n';
return;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3756kb
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: 3520kb
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: 3556kb
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:
3800 1068 877 516 2668 3559 1165 3373 560 925 3502 696 3824 1746 2970 1826 613 2221 1130 4677 1900 1646 492 273 3203 6572 1070 3330 1024 765 142 3038 1615 9445 2122 220 1741 2561 1145 480 2094 5119 5214 2446 3929 2249 4378 4927 2356 1473 2944 1574 1990 1609 3136 2298 1459 2663 2617 2254 3986 215 420...
result:
wrong answer 1st numbers differ - expected: '3857', found: '3800'