QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#611933#9415. Matrixshiqiaqiaya#RE 0ms0kbC++173.8kb2024-10-05 00:27:412024-10-05 00:27:46

Judging History

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

  • [2024-10-05 00:27:46]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-05 00:27:41]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define int long long
using i64 = long long;
using i128 = __int128;
mt19937_64 rd(time(0));
template <class K, class C = less<>> using paring_heap = __gnu_pbds::priority_queue<K, C>;
template <class K> using rb_tree = tree<K, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T, class ... A> void debug(const T & t, const A & ... a) { cerr << "[" << t, ((cerr << ", " << a), ...), cerr << "]\n"; }
const i64 mod = [](bool n) { return n ? 998244353 : 1e9 + 7; } (1);

const double pi = acos(-1);

struct point : array<int, 2> {   // int 遇到奇怪问题可重载各种比较符号
    int operator * (const point & t) { return at(0) * t[1] - at(1) * t[0]; }  // 叉积
    int operator / (const point & t) { return at(0) * t[0] + at(1) * t[1]; }  // 内积
    point & operator += (const point & t) { return at(0) += t[0], at(1) += t[1], *this; }
    point operator + (const point & t) { return point(*this) += t; }
    point & operator -= (const point & t) { return at(0) -= t[0], at(1) -= t[1], *this; }
    point operator - (const point & t) { return point(*this) -= t; }
    point & operator *= (const int & t) { return at(0) *= t, at(1) *= t, *this; }
    point operator * (const int & t) { return point(*this) *= t; }
    point & operator /= (const int & t) { return at(0) /= t, at(1) /= t, *this; }
    point operator / (const int & t) { return point(*this) /= t; }
};

void QAQ() {
    int n;
    cin >> n;

    vector<point> a(2 * n);
    vector<int> c(n);

    for (auto & x : c) {
        cin >> x;
    }
    c.resize(2 * n);
    for (int i = 0; i < n; i++) {
        cin >> a[i][0] >> a[i][1];
        c[i + n] = c[i];
        a[i + n] = a[i];
    }

    point o = {(int)2e9, (int)2e9};
    // point o = {0, 0};
    // point o = {45, 45};

    vector dp(2 * n, vector<array<int, 3>>(2 * n, {-1, -1, -1}));
    auto vis = dp;

    auto dfs = [&](auto && self, int l, int r, int op) -> int {
        if (l > r || vis[l][r][op] != -1) return dp[l][r][op];
        vis[l][r][op] = 0;
        if (l == r) return dp[l][r][op] = op == 2 ? 0 : -1;
        if (op == 2) {
            dp[l][r][op] = a[l] * a[r];
            for (int i = l + 1; i < r; i++) {
                auto t1 = self(self, i, r, 0), t2 = self(self, l, i, 1);
                if (t1 != -1) {
                    dp[l][r][op] = max(dp[l][r][op], (a[l] - o) * (a[i] - o) + t1);
                } if (t2 != -1) {
                    dp[l][r][op] = max(dp[l][r][op], (a[i] - o) * (a[r] - o) + t2);
                }
            }
        } else if (op == 0) {
            for (int i = l; i < r; i++) if (c[l] == c[i]) {
                auto t = self(self, l, i, 2);
                if (t != -1) {
                    dp[l][r][op] = max(dp[l][r][op], (a[i] - o) * (a[r] - o) + t);
                }
            }
        } else {
            for (int i = l + 1; i <= r; i++) if (c[i] == c[r]) {
                auto t = self(self, i, r, 2);
                if (t != -1) {
                    dp[l][r][op] = max(dp[l][r][op], (a[l] - o) * (a[i] - o) + t);
                }
            }
        }

        return dp[l][r][op];
    };

    int ans = 0;

    for (int i = 0; i < 2 * n; i++) {
        for (int j = i; j < 2 * n && (j - i + 1) <= n; j++) if (c[i] == c[j]) {
            auto t = dfs(dfs, i, j, 2);
            if (t != -1) {
                ans = max(ans, t + (a[j] - o) * (a[i] - o));
            }
        }
    }

    cout << ans << "\n";
}

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    int t = 1;
    cin >> t;
    for (cout << fixed << setprecision(12); t--; QAQ());
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

2

output:


result: