QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#335705#1169. Generate The ArrayAaronwrqWA 187ms449112kbC++142.1kb2024-02-23 20:05:302024-02-23 20:05:30

Judging History

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

  • [2024-02-23 20:05:30]
  • 评测
  • 测评结果:WA
  • 用时:187ms
  • 内存:449112kb
  • [2024-02-23 20:05:30]
  • 提交

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 long cprod(Point a, Point b) {return (__int128)a.x * b.y - (__int128)a.y * b.x;}
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: 18008kb

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

input:

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

output:

-145

result:

ok 1 number(s): "-145"

Test #3:

score: 0
Accepted
time: 177ms
memory: 267508kb

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:

451781489678

result:

ok 1 number(s): "451781489678"

Test #4:

score: 0
Accepted
time: 172ms
memory: 266836kb

input:

300
511 90 199 774 41 709 63 613 729 314 625 45 968 799 520 341 82 12 521 711 47 776 384 836 84 42 657 949 232 632 791 162 503 364 568 287 699 57 454 106 846 419 136 327 728 748 551 260 167 616 329 789 362 362 122 529 838 684 78 243 681 356 744 154 474 345 967 137 175 194 819 992 940 215 364 145 755...

output:

448802887313

result:

ok 1 number(s): "448802887313"

Test #5:

score: 0
Accepted
time: 155ms
memory: 280264kb

input:

300
639 743 456 955 294 974 238 305 884 201 769 789 58 40 843 258 997 275 244 656 796 65 893 707 645 250 174 810 544 310 17 137 603 500 380 887 724 836 795 513 242 637 917 781 429 832 362 96 889 570 739 841 160 990 18 467 428 305 637 47 897 165 79 728 209 710 48 261 774 328 664 74 659 727 136 575 40...

output:

450025318634

result:

ok 1 number(s): "450025318634"

Test #6:

score: 0
Accepted
time: 163ms
memory: 278116kb

input:

300
63 587 202 433 356 751 925 589 552 383 208 341 852 474 358 175 719 25 262 409 544 843 210 90 502 458 395 375 857 477 243 215 190 932 193 295 158 207 737 728 239 752 697 940 322 211 174 340 507 741 661 597 741 811 210 702 315 926 684 555 600 782 119 709 240 268 537 384 565 654 213 564 675 134 11 ...

output:

450583665163

result:

ok 1 number(s): "450583665163"

Test #7:

score: 0
Accepted
time: 172ms
memory: 281104kb

input:

300
191 728 756 614 609 528 397 281 411 861 944 380 943 715 977 796 145 287 280 354 485 621 719 769 359 179 320 428 977 347 661 782 481 69 494 896 184 282 975 134 340 970 990 394 318 999 985 584 421 696 479 136 538 439 618 640 906 547 835 167 111 887 454 283 463 633 513 508 163 788 866 647 690 646 8...

output:

450891112678

result:

ok 1 number(s): "450891112678"

Test #8:

score: 0
Accepted
time: 151ms
memory: 280812kb

input:

300
911 572 309 284 863 496 84 269 567 747 88 124 33 444 4 905 60 845 2 402 937 207 525 153 920 387 837 585 289 513 887 860 68 501 603 304 618 357 212 53 633 84 475 849 507 275 797 420 39 355 888 892 823 259 810 682 689 872 690 972 815 504 789 265 198 998 298 928 954 626 415 241 409 158 466 570 476 ...

output:

450773173363

result:

ok 1 number(s): "450773173363"

Test #9:

score: 0
Accepted
time: 160ms
memory: 333840kb

input:

300
40 416 759 466 925 273 67 553 426 930 527 164 827 685 815 822 486 596 20 347 686 688 34 832 777 595 58 150 410 384 113 835 463 637 416 904 347 920 450 460 733 495 552 7 696 62 904 664 657 821 706 944 108 784 2 917 872 493 441 480 926 121 828 543 230 852 787 755 553 760 259 27 424 670 533 704 636...

output:

451862446420

result:

ok 1 number(s): "451862446420"

Test #10:

score: 0
Accepted
time: 144ms
memory: 317440kb

input:

300
464 261 313 943 178 346 539 437 582 112 671 419 726 414 842 739 401 154 446 588 627 466 351 407 338 803 280 203 722 254 531 209 458 366 716 312 77 699 687 570 26 417 37 166 693 146 420 908 379 480 820 188 202 708 898 855 463 114 296 92 437 930 163 821 261 217 764 879 856 894 616 814 247 373 408 ...

output:

451022179903

result:

ok 1 number(s): "451022179903"

Test #11:

score: 0
Accepted
time: 168ms
memory: 339296kb

input:

300
888 913 762 125 432 315 226 425 737 294 110 459 112 656 653 656 123 608 464 341 375 348 565 790 899 228 797 64 138 124 54 479 45 502 529 912 807 70 925 785 319 532 330 812 881 933 527 448 997 947 229 240 487 232 794 90 53 439 639 896 141 843 10 906 996 878 549 299 647 220 461 896 262 885 692 564...

output:

450801726353

result:

ok 1 number(s): "450801726353"

Test #12:

score: 0
Accepted
time: 154ms
memory: 341336kb

input:

300
959 874 797 575 298 535 645 718 947 327 80 257 467 71 174 919 541 399 85 508 103 379 637 811 13 99 989 961 766 355 124 786 45 812 800 769 593 585 67 293 549 387 368 134 281 902 715 716 471 921 342 680 727 858 29 209 427 736 171 225 628 495 226 950 939 712 864 561 152 558 148 602 527 113 509 282 ...

output:

451693457699

result:

ok 1 number(s): "451693457699"

Test #13:

score: 0
Accepted
time: 173ms
memory: 357020kb

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:

451118727187

result:

ok 1 number(s): "451118727187"

Test #14:

score: 0
Accepted
time: 162ms
memory: 380724kb

input:

300
511 90 199 774 41 709 63 613 729 314 625 45 968 799 520 341 82 12 521 711 47 776 384 836 84 42 657 949 232 632 791 162 503 364 568 287 699 57 454 106 846 419 136 327 728 748 551 260 167 616 329 789 362 362 122 529 838 684 78 243 681 356 744 154 474 345 967 137 175 194 819 992 940 215 364 145 755...

output:

448135681077

result:

ok 1 number(s): "448135681077"

Test #15:

score: 0
Accepted
time: 152ms
memory: 379808kb

input:

300
639 743 456 955 294 974 238 305 884 201 769 789 58 40 843 258 997 275 244 656 796 65 893 707 645 250 174 810 544 310 17 137 603 500 380 887 724 836 795 513 242 637 917 781 429 832 362 96 889 570 739 841 160 990 18 467 428 305 637 47 897 165 79 728 209 710 48 261 774 328 664 74 659 727 136 575 40...

output:

449362743284

result:

ok 1 number(s): "449362743284"

Test #16:

score: 0
Accepted
time: 164ms
memory: 361964kb

input:

300
63 587 202 433 356 751 925 589 552 383 208 341 852 474 358 175 719 25 262 409 544 843 210 90 502 458 395 375 857 477 243 215 190 932 193 295 158 207 737 728 239 752 697 940 322 211 174 340 507 741 661 597 741 811 210 702 315 926 684 555 600 782 119 709 240 268 537 384 565 654 213 564 675 134 11 ...

output:

449892590405

result:

ok 1 number(s): "449892590405"

Test #17:

score: 0
Accepted
time: 151ms
memory: 393348kb

input:

300
191 728 756 614 609 528 397 281 411 861 944 380 943 715 977 796 145 287 280 354 485 621 719 769 359 179 320 428 977 347 661 782 481 69 494 896 184 282 975 134 340 970 990 394 318 999 985 584 421 696 479 136 538 439 618 640 906 547 835 167 111 887 454 283 463 633 513 508 163 788 866 647 690 646 8...

output:

450222744293

result:

ok 1 number(s): "450222744293"

Test #18:

score: 0
Accepted
time: 151ms
memory: 393920kb

input:

300
911 572 309 284 863 496 84 269 567 747 88 124 33 444 4 905 60 845 2 402 937 207 525 153 920 387 837 585 289 513 887 860 68 501 603 304 618 357 212 53 633 84 475 849 507 275 797 420 39 355 888 892 823 259 810 682 689 872 690 972 815 504 789 265 198 998 298 928 954 626 415 241 409 158 466 570 476 ...

output:

450090999665

result:

ok 1 number(s): "450090999665"

Test #19:

score: 0
Accepted
time: 145ms
memory: 419372kb

input:

300
40 416 759 466 925 273 67 553 426 930 527 164 827 685 815 822 486 596 20 347 686 688 34 832 777 595 58 150 410 384 113 835 463 637 416 904 347 920 450 460 733 495 552 7 696 62 904 664 657 821 706 944 108 784 2 917 872 493 441 480 926 121 828 543 230 852 787 755 553 760 259 27 424 670 533 704 636...

output:

451201756518

result:

ok 1 number(s): "451201756518"

Test #20:

score: 0
Accepted
time: 127ms
memory: 436152kb

input:

300
464 261 313 943 178 346 539 437 582 112 671 419 726 414 842 739 401 154 446 588 627 466 351 407 338 803 280 203 722 254 531 209 458 366 716 312 77 699 687 570 26 417 37 166 693 146 420 908 379 480 820 188 202 708 898 855 463 114 296 92 437 930 163 821 261 217 764 879 856 894 616 814 247 373 408 ...

output:

450331334287

result:

ok 1 number(s): "450331334287"

Test #21:

score: 0
Accepted
time: 169ms
memory: 439156kb

input:

300
888 913 762 125 432 315 226 425 737 294 110 459 112 656 653 656 123 608 464 341 375 348 565 790 899 228 797 64 138 124 54 479 45 502 529 912 807 70 925 785 319 532 330 812 881 933 527 448 997 947 229 240 487 232 794 90 53 439 639 896 141 843 10 906 996 878 549 299 647 220 461 896 262 885 692 564...

output:

450132895974

result:

ok 1 number(s): "450132895974"

Test #22:

score: 0
Accepted
time: 155ms
memory: 446848kb

input:

300
959 874 797 575 298 535 645 718 947 327 80 257 467 71 174 919 541 399 85 508 103 379 637 811 13 99 989 961 766 355 124 786 45 812 800 769 593 585 67 293 549 387 368 134 281 902 715 716 471 921 342 680 727 858 29 209 427 736 171 225 628 495 226 950 939 712 864 561 152 558 148 602 527 113 509 282 ...

output:

451032042761

result:

ok 1 number(s): "451032042761"

Test #23:

score: -100
Wrong Answer
time: 187ms
memory: 449112kb

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:

1863921890986715

result:

wrong answer 1st numbers differ - expected: '2221033350629661', found: '1863921890986715'