QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#610893#9417. Palindromic PolygonRosmontispesWA 0ms36268kbC++204.1kb2024-10-04 17:58:062024-10-04 17:58:07

Judging History

你现在查看的是最新测评结果

  • [2024-10-04 17:58:07]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:36268kb
  • [2024-10-04 17:58:06]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1000 + 20;
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; 
}
struct node{
    long long sum;
    vector<Point>p;
}g[N][N];
long long count(vector<Point>res){
    long long S = 0;
    // cout<<"----------------------------\n";
    for(int i = 0;i < (int)res.size();i ++){
        // cout<<res[i].x<<" "<<res[i].y<<"\n";
        int nex = i + 1 == (int)res.size()?0:i + 1;
        S += cross(res[i],res[nex]);
    }

    // cout<<S<<"\n";
    return 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];
    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].p.clear(),g[i][j].sum = 0;
    for(int i = 0;i < 2 * n;i ++)
        g[i][i].p.push_back(p[i]);
    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].sum = 0;
                g[i][i + len - 1].p.push_back(p[i]);
                g[i][i + len - 1].p.push_back(p[i + len - 1]);

                if(g[i][i + len - 2].sum > g[i][i + len - 1].sum)
                    g[i][i + len - 1] = g[i][i + len - 2];
                if(g[i + 1][i + len - 1].sum > g[i][i + len - 1].sum)
                    g[i][i + len - 1] = g[i + 1][i + len - 1];

                int L = i + 1,R = i + len - 2;
                for(int j = L;j <= R;j ++){
                    if(f[j] != f[R])
                        continue;
                    vector<Point>res;
                    res.push_back(p[i]);
                    for(auto v:g[j][R].p)
                        res.push_back(v);
                    res.push_back(p[i + len - 1]);
                    auto sum = count(res) + g[j][R].sum;
                    if(sum >= g[i][i + len - 1].sum){
                        g[i][i + len - 1].sum = sum;
                        g[i][i + len - 1].p.clear();
                        g[i][i + len - 1].p.push_back(p[i]);
                        g[i][i + len - 1].p.push_back(p[i + len - 1]);
                    }
                }
                for(int j = L;j <= R;j ++){
                    if(f[L] != f[j])
                        continue;
                    vector<Point>res;
                    res.push_back(p[i]);
                    for(auto v:g[L][j].p)
                        res.push_back(v);
                    res.push_back(p[i + len - 1]);
                    auto sum = count(res) + g[L][j].sum;
                    if(sum >= g[i][i + len - 1].sum){
                        g[i][i + len - 1].sum = sum;
                        g[i][i + len - 1].p.clear();
                        g[i][i + len - 1].p.push_back(p[i]);
                        g[i][i + len - 1].p.push_back(p[i + len - 1]);
                    }
                }
            } else {
                int L = i,R = i + len - 1;
                for(int j = L;j <= R;j ++){
                    if(f[j] != f[R])
                        continue;
                    if(g[j][R].sum >= g[i][i + len - 1].sum){
                        g[i][i + len - 1] = g[j][R];
                    }
                }
                for(int j = L;j <= R;j ++){
                    if(f[L] != f[j])
                        continue;
                    if(g[L][j].sum >= g[i][i + len - 1].sum){
                        g[i][i + len - 1] = g[L][j];
                    }
                } 
            }
        }
    }
    long long ans = 0;
    for(int i = 0;i < n;i ++)
        ans = max(ans,g[i][i + n - 1].sum);
    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();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 36052kb

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: 36268kb

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: 0ms
memory: 36120kb

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
2449
3559
1165
3333
560
435
2287
696
3653
1746
2970
1826
613
1682
1083
4671
1798
1646
492
273
3151
6572
1070
3122
1024
765
142
2720
1615
9445
2026
220
1741
2561
1145
232
2094
5119
5214
1590
3929
1684
4378
4927
2356
1473
2944
1574
1990
1609
2036
2298
1008
2663
2617
2254
3986
215
420...

result:

wrong answer 1st numbers differ - expected: '3857', found: '3800'