QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#596375#9434. Italian Cuisineucup-team3646#WA 0ms3808kbC++232.4kb2024-09-28 15:38:502024-09-28 15:38:51

Judging History

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

  • [2024-09-28 15:38:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3808kb
  • [2024-09-28 15:38:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll=long long;

// pragma
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")


ll X[510],Y[510];
ll DP[510][510];
inline ll area(int i,int j,int k){
    ll ax=X[j]-X[i];
    ll ay=Y[j]-Y[i];
    ll bx=X[k]-X[i];
    ll by=Y[k]-Y[i];
    return abs(ax*by-ay*bx);
};


void solve(){
  int N;
  cin>>N;
  vector<int> A(N);
  map<int,int> MA;
  for(int i=0;i<N;i++){
    cin>>A[i];
    MA[A[i]]=1;
  }
  int cnt=0;
  for(auto m:MA)MA[m.first]=cnt,cnt++;
  for(int i=0;i<N;i++)A[i]=MA[A[i]];

  for(int i=0;i<N;i++)cin>>X[i]>>Y[i];



  vector<vector<int>> nextR(N),nextL(N);
  vector<int> col(cnt,-1); 
  for(int i=0;i<2*N;i++){
    if(i>=N){
      nextL[i-N]=col;
    }
    col[A[i%N]]=i%N;
  }
  for(int i=2*N-1;i>=0;i--){
    if(i<N)nextR[i]=col;
    col[A[i%N]]=i%N;
  }

  // vector<vector<ll>> DP(N,vector<ll>(N,-1e18));
  for(int i=0;i<N;i++)for(int j=0;j<N;j++)DP[i][j]=-1e18;
  ll an=0;
  for(int d=0;d<N;d++){
    for(int L=0;L<N;L++){
      int R=(L+d)%N;
      if(A[L]!=A[R])continue;
      DP[L][R]=max(DP[L][R],0ll);
      an=max(an,DP[L][R]);
      //
      {
        vector<bool>seen(cnt,false);
        int k=L-1;
        if(k<0)k+=N;
        while(k!=R){
          int c=A[k];
          if(seen[c]){
            k--;
            if(k<0)k+=N;
            continue;
          }
          seen[c]=1;
          int x=nextR[R][c];
          while(x!=k){
            // assert(A[x]==c);
            // cout<<L<<" "<<R<<" "<<c<<" "<<x<<" "<<k<<endl;
            DP[k][x]=max(DP[k][x],DP[L][R]+area(L,R,k)+area(R,x,k));
            x=nextR[x][c];
          }

          k--;
          if(k<0)k+=N;
        }
      }
      //
      {
        vector<bool> seen(cnt,false);
        int k=R+1;
        if(k>=N)k-=N;
        while(k!=L){
          int c=A[k];
          if(seen[c]){
            k++;
            if(k>=N)k-=N;
            continue;
          }
          seen[c]=1;
          int x=nextL[L][c];
          while(x!=k){
            DP[x][k]=max(DP[x][k],DP[L][R]+area(L,R,k)+area(L,x,k));
            x=nextL[x][c];
          }

          k++;
          if(k>=N)k-=N;
        }
      }


    }
  }
  cout<<an<<endl;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int T;
  cin>>T;
  while(T--)solve();
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3808kb

input:

3
5
1 1 1
0 0
1 0
5 0
3 3
0 5
6
2 4 1
2 0
4 0
6 3
4 6
2 6
0 3
4
3 3 1
3 0
6 3
3 6
0 3

output:

52
0
6

result:

wrong answer 1st numbers differ - expected: '5', found: '52'