QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#610968 | #9417. Palindromic Polygon | Rosmontispes | WA | 1ms | 3852kb | C++20 | 3.7kb | 2024-10-04 18:21:50 | 2024-10-04 18:21:50 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1000 + 200;
const long long inf = 0x3f3f3f3f3f3f3f3f;
struct Point{
long long x,y;
Point(long long _x = 0,long long _y = 0):x(_x),y(_y){}
};
long long cross(Point a,Point b){
return a.x * b.y - a.y * b.x;
}
long long g[N][N];
long long count(vector<Point>res){
long long S = 0;
for(int i = 0;i < (int)res.size();i ++){
int nex = i + 1 == (int)res.size()?0:i + 1;
S += cross(res[i],res[nex]);
}
assert(S >= 0);
return llabs(S);
}
void solve()
{
int n;
cin>>n;
vector<int>f(2 * n);
vector<Point>p(2 * n);
for(int i = 0;i < n;i ++)
cin>>f[i],f[i + n] = f[i];
map<int,vector<int>>M;
for(int i = 0;i < 2 * n;i ++)
M[f[i]].push_back(i);
for(int i = 0;i < n;i ++){
long long x,y;
cin>>x>>y;
p[i] = Point(x,y);
p[i + n] = Point(x,y);
}
for(int i = 0;i <= 2 * n;i ++)
for(int j = 0;j <= 2 * n;j ++)
g[i][j] = -inf;
for(int i = 0;i < 2 * n;i ++)
g[i][i] = 0;
long long ans = 0;
vector<int>vis(2 * n);
for(int len = 2;len <= n;len ++){
for(int i = 0;i < n;i ++){
if(f[i] == f[i + len - 1]){
g[i][i + len - 1] = max(g[i][i + len - 1],0ll);
for(int j = i + 1;j <= i + len - 2;j ++){
if(vis[j])
continue;
auto &vec = M[f[j]];
auto il = lower_bound(vec.begin(),vec.end(),i + 1);
auto ir = lower_bound(vec.begin(),vec.end(),i + len - 1);
ir --;
vector<Point>res;
for(auto it = ir;it != il;it --){
res.clear();
res.push_back(p[i]);
if(*il == *it)
res.push_back(p[*il]);
else
res.push_back(p[*il]),res.push_back(p[*it]);
res.push_back(p[i + len - 1]);
long long sum = count(res) + g[*il][*it];
ans = max(ans,sum);
g[i][i + len - 1] = max(g[i][i + len - 1],sum);
}
for(auto it = il;it != ir;it ++){
res.clear();
res.push_back(p[i]);
if(*ir == *it)
res.push_back(p[*ir]);
else
res.push_back(p[*it]),res.push_back(p[*ir]);
res.push_back(p[i + len - 1]);
long long sum = count(res) + g[*it][*ir];
ans = max(ans,sum);
g[i][i + len - 1] = max(g[i][i + len - 1],sum);
}
ir ++;
for(auto it = il;it != ir;it ++){
vis[*it] = 1;
res.clear();
res.push_back(p[i]);
res.push_back(p[*it]);
res.push_back(p[i + len - 1]);
long long sum = count(res) + g[*it][*it];
ans = max(ans,sum);
g[i][i + len - 1] = max(g[i][i + len - 1],sum);
}
}
for(int j = i + 1;j <= i + len - 2;j ++)
vis[j] = 0;
}
}
}
cout<<ans<<"\n";
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cout<<fixed<<setprecision(12);
int T=1;
cin>>T;
while(T--)
{
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3676kb
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: 3852kb
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: 3692kb
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 877 516 2496 3559 1165 3468 560 925 3502 696 3653 1746 2970 1826 613 1682 1083 4677 1900 1646 564 273 3151 6572 1070 3122 1024 765 142 3038 1615 9445 2026 320 1741 2561 1145 480 2094 5119 5458 1590 3929 2249 4378 4927 2356 1473 3152 1574 1990 1609 2402 2298 1391 2663 2617 2298 4048 215 546...
result:
wrong answer 5th numbers differ - expected: '2668', found: '2496'