QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#598852#9417. Palindromic Polygonucup-team008#WA 0ms3588kbC++175.6kb2024-09-28 23:41:492024-09-28 23:41:51

Judging History

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

  • [2024-09-28 23:41:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3588kb
  • [2024-09-28 23:41:49]
  • 提交

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>> colordp;
  {
    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();
    colordp.resize(sz(disc));
    for(int i = 0; i < sz(colordp); i++) colordp[i].assign(2*n, -1);
    for(int i = 0; i < 2*n; i++) colordp[colors[i]][i] = i;
    for(int i = 0; i < sz(colordp); i++) {
      for(int j = 1; j < 2*n; j++) {
        updmax(colordp[i][j], colordp[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;
    dp[lhs][rhs] = 0;
    for(int i = lhs+1; i < rhs; i++) {
      int ni = colordp[colors[i]][rhs-1];
      assert(ni >= i);
      updmax(dp[lhs][rhs], self(i, ni) - v[ni%n].cross(v[i%n]) + v[lhs].cross(v[i]) + v[ni].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();
}

詳細信息

Test #1:

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

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: -100
Wrong Answer
time: 0ms
memory: 3560kb

input:

1
4
1000000000 1000000000 1000000000 1000000000
-1000000000 -1000000000
1000000000 -1000000000
1000000000 1000000000
-1000000000 1000000000

output:

6000000000000000000

result:

wrong answer 1st numbers differ - expected: '8000000000000000000', found: '6000000000000000000'