QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#598987#9417. Palindromic Polygonucup-team008#WA 1ms3784kbC++176.2kb2024-09-29 00:28:512024-09-29 00:28:56

Judging History

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

  • [2024-09-29 00:28:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3784kb
  • [2024-09-29 00:28:51]
  • 提交

answer

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
#define derr if(0) cerr
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << flush;
// END NO SAD

template<class Fun>
class y_combinator_result {
  Fun fun_;
public:
  template<class T>
  explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}

  template<class ...Args>
  decltype(auto) operator()(Args &&...args) {
    return fun_(std::ref(*this), std::forward<Args>(args)...);
  }
};

template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
  return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

template<class T>
bool updmin(T& a, T b) {
  if(b < a) {
    a = b;
    return true;
  }
  return false;
}
template<class T>
bool updmax(T& a, T b) {
  if(b > a) {
    a = b;
    return true;
  }
  return false;
}
typedef int64_t ll;
typedef long double ld;

template<class T>
struct Point {
	typedef Point P;
	T x, y;
	explicit Point(T x=0, T y=0) : x(x), y(y) {}
	bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
	bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
	P operator+(P p) const { return P(x+p.x, y+p.y); }
	P operator-(P p) const { return P(x-p.x, y-p.y); }
	P operator*(T d) const { return P(x*d, y*d); }
	P operator/(T d) const { return P(x/d, y/d); }
	T dot(P p) const { return x*p.x + y*p.y; }
	T cross(P p) const { return x*p.y - y*p.x; }
	T cross(P a, P b) const { return (a-*this).cross(b-*this); }
	T dist2() const { return x*x + y*y; }
	ld dist() const { return sqrtl(dist2()); }
	// angle to x-axis in interval [-pi, pi]
	double angle() const { return atan2(y, x); }
	P unit() const { return *this/dist(); } // makes dist()=1
	P perp() const { return P(-y, x); } // rotates +90 degrees
	P normal() const { return perp().unit(); }
	// returns point rotated 'a' radians ccw around the origin
	P rotate(double a) const {
		return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
};

typedef Point<ll> P;

void rsolve() {
  int n;
  cin >> n;
  vector<int> colors(2*n);
  for(int i = 0; i < n; i++) {
    cin >> colors[i];
    colors[i+n] = colors[i];
  }
  vector<vector<int>> colormaxdp, colormindp;
  {
    vector<int> disc = colors;
    sort(all(disc));
    disc.erase(unique(all(disc)), disc.end());
    for(int i = 0; i < 2*n; i++) colors[i] = lower_bound(all(disc), colors[i]) - disc.begin();
    colormaxdp.resize(sz(disc));
    for(int i = 0; i < sz(colormaxdp); i++) colormaxdp[i].assign(2*n, -1);
    for(int i = 0; i < 2*n; i++) colormaxdp[colors[i]][i] = i;
    for(int i = 0; i < sz(colormaxdp); i++) {
      for(int j = 1; j < 2*n; j++) {
        updmax(colormaxdp[i][j], colormaxdp[i][j-1]);
      }
    }
    colormindp.resize(sz(disc));
    for(int i = 0; i < sz(colormindp); i++) colormindp[i].assign(2*n, 2*n);
    for(int i = 0; i < 2*n; i++) colormindp[colors[i]][i] = i;
    for(int i = 0; i < sz(colormindp); i++) {
      for(int j = 2*n-2; j >= 0; j--) {
        updmin(colormindp[i][j], colormindp[i][j+1]);
      }
    }
  }
  vector<P> v(2*n);
  for(int i = 0; i < n; i++) {
    cin >> v[i].x >> v[i].y;
    v[i+n] = v[i];
  }
  vector<vector<ll>> dp(2*n);
  auto dfs = y_combinator([&](auto self, int lhs, int rhs) -> ll {
    if(dp[lhs][rhs] >= 0) return dp[lhs][rhs];
    if(lhs == rhs) return 0;
    if(lhs+1 == rhs) return 0;
    dp[lhs][rhs] = 0;
    for(int i = lhs+1; i < rhs; i++) {
      int ni = colormaxdp[colors[i]][rhs-1];
      assert(ni >= i);
      updmax(dp[lhs][rhs], self(i, ni) - v[ni].cross(v[i]) + v[lhs].cross(v[i]) + v[ni].cross(v[rhs]));
      ni = colormindp[colors[i]][lhs+1];
      assert(ni <= i);
      updmax(dp[lhs][rhs], self(ni, i) - v[i].cross(v[ni]) + v[lhs].cross(v[ni]) + v[i].cross(v[rhs]));
    }
    dp[lhs][rhs] += v[rhs].cross(v[lhs]);
    return dp[lhs][rhs];
  });
  for(auto& x: dp) x.assign(2*n, -1);
  ll ret = 0;
  for(int i = 0; i < n; i++) {
    for(int j = i+1; j < i+n; j++) {
      if(colors[i] == colors[j%n]) {
        updmax(ret, dfs(i, j));
      }
    }
  }
  cout << ret << "\n";
}
void solve() {
  int t;
  cin >> t;
  while(t--) rsolve();
}

// what would chika do
// are there edge cases (N=1?)
// are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// integer overflow?
// DS reset properly between test cases
// are you doing geometry in floating points
// are you not using modint when you should

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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:

10363
8052
5595
4506
12151
10061
4880
11325
2675
4665
10209
7602
16648
8259
14104
7928
1678
8991
8025
15895
11964
9800
3636
3160
12794
13726
10196
12228
6002
7015
1385
13932
8514
9445
11098
4925
9805
9792
13162
2373
11455
19520
17392
2446
13339
10465
20146
16766
10411
4428
12971
7600
15506
4888
8443...

result:

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