QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#335704#1169. Generate The ArrayAaronwrqWA 130ms279528kbC++142.1kb2024-02-23 20:04:402024-02-23 20:04:41

Judging History

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

  • [2024-02-23 20:04:41]
  • 评测
  • 测评结果:WA
  • 用时:130ms
  • 内存:279528kb
  • [2024-02-23 20:04:40]
  • 提交

answer

#include <bits/stdc++.h>
#define MAXN 310
#define MAXK 300010
using namespace std;

int n, k, tot;
long long a[MAXN][MAXN], s[MAXN][MAXN], w[MAXN][MAXN][MAXN], val[MAXN][MAXN][MAXN], dp[MAXN][MAXN];
const long long inf = 0x3f3f3f3f3f3f3f3fll;
struct Point{long long x, y;};
Point b[MAXK], h[MAXK];

bool cmp(const Point a, const Point b) {return a.x == b.x ? a.y < b.y : a.x < b.x;}
Point operator-(Point a, Point b) {a.x -= b.x, a.y -= b.y; return a;}
long double cprod(Point a, Point b) {return (long double)a.x / b.x - (long double)a.y / b.y;}
long long getb(const long long k, const Point a) {return a.y - a.x * k;}
void Add(const Point a) {
	while (tot > 1 && cprod(h[tot] - h[tot - 1], a - h[tot]) >= 0) --tot;
	h[++tot] = a;
	return;
}

long long getval(const long long k) {
	int l = 1, r = tot, mid;
	while (l < r) {
		mid = (l + r) >> 1;
		if (getb(k, h[mid]) < getb(k, h[mid + 1])) l = mid + 1;
		else r = mid;
	}
	return getb(k, h[l]);
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i) for (int j = i; j <= n; ++j) cin >> a[i][j];
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) s[i][j] = s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1] + a[i][j];
	for (int i = 1; i <= n; ++i) for (int j = i; j <= n; ++j) for (int k = i; k <= j; ++k) w[k][i][j] = s[k][j] - s[k][k - 1] - s[i - 1][j] + s[i - 1][k - 1];
	for (int i = 1; i <= n; ++i) {
		cin >> k; tot = 0;
		for (int j = 1; j <= k; ++j) {
			long long v, c; cin >> v >> c;
			b[j] = Point{-v, -c};
		}
		sort(b + 1, b + k + 1, cmp);
		for (int j = 1; j <= k; ++j) Add(b[j]);
		// for (int j = 1; j <= tot; ++j) cout << h[j].x << " " << h[j].y << "\n";
		for (int l = 1; l <= i; ++l) for (int r = i; r <= n; ++r) {
			val[i][l][r] = getval(w[i][l][r]);
		}
	}
	for (int len = 1; len <= n; ++len) for (int l = 1, r = len; r <= n; ++l, ++r) {
		dp[l][r] = -inf;
		for (int p = l; p <= r; ++p) dp[l][r] = max(dp[l][r], dp[l][p - 1] + dp[p + 1][r] + val[p][l][r]);
	}
	// for (int i = 1; i <= n; ++i, cout << "\n") for (int l = 1; l <= i; ++l, cout << "\n") for (int r = i; r <= n; ++r) cout << val[i][l][r] << " ";
	cout << dp[1][n] << "\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 0 2 2 0
0 2 2 0
2 2 2
1 2
0
2
0 27
1 19
2
7 25
1 1
2
8 7
4 18
2
8 7
4 4
2
0 25
4 26

output:

78

result:

ok 1 number(s): "78"

Test #2:

score: 0
Accepted
time: 2ms
memory: 13956kb

input:

2
1 1
1
2
1 100
2 50
1
1 100

output:

-145

result:

ok 1 number(s): "-145"

Test #3:

score: -100
Wrong Answer
time: 130ms
memory: 279528kb

input:

300
791 246 453 104 979 932 79 625 573 836 378 302 70 70 5 424 656 262 799 471 107 998 874 452 227 26 435 896 816 466 372 596 212 931 459 879 265 686 216 996 553 304 547 680 540 961 931 16 549 445 512 545 781 542 930 295 247 359 927 631 978 738 409 364 443 980 286 13 576 356 462 909 821 703 489 10 5...

output:

451468551909

result:

wrong answer 1st numbers differ - expected: '451781489678', found: '451468551909'