QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#810466#978. Maximum Subsequencerlc202204WA 1005ms11820kbC++233.2kb2024-12-11 22:55:462024-12-11 22:55:51

Judging History

This is the latest submission verdict.

  • [2024-12-11 22:55:51]
  • Judged
  • Verdict: WA
  • Time: 1005ms
  • Memory: 11820kb
  • [2024-12-11 22:55:46]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 20;
const int inf = ~0x3f3f3f3f;

int n;
int a[N] = {0};
int b[N] = {0};

typedef pair<int, int> pii;

pii slv1(int *arr, int len) {
	int ans = inf, dp = inf;
	for (int i = 1; i <= len; i++) {
		dp = max(arr[i], arr[i] + dp);
		ans = max(ans, dp);
	}
	int mx = inf;
	dp = 0;
	for (int i = 1; i <= len; i++)
		dp += arr[i], mx = max(mx, dp);
		
//	for (int i = 1; i <= len; i++)
//		cout << arr[i] << " ";
//	cout << " ?? " << ans << " " << mx << endl;
		
	return make_pair(ans, mx);
}

int p[N] = {0};
int tmp[N] = {0};

const int M = 5e4 + 5;

int allL[M][N] = {{0}};
int totl, totr;
int allR[M][N] = {{0}};


pii A[M], B[M];
pii C[M];

int ANS = 2e9;

void slv(pii *arr, int &len) {
	sort(arr + 1, arr + len + 1);
	int mn = 2e9, cur = 0;
	for (int i = 1; i <= len; i++)
		if (arr[i].second < mn)
			mn = arr[i].second, C[++cur] = arr[i];
	len = cur;
	for (int i = 1; i <= cur; i++)
		arr[i] = C[i];
}

int calc() {
	int L = (n + 1) / 2;
	int R = n - L;
	int tl = 0;
	for (int t = 1; t <= totl; t++) {
		for (int i = 1; i <= L; i++)
			tmp[i] = a[allL[t][i]];
		pii ttt = slv1(tmp, L);
		if (ttt.first <= ANS)
			A[++tl] = ttt;
	}
	
	int tr = 0;
	for (int t = 1; t <= totr; t++) {
		for (int i = 1; i <= R; i++)
			tmp[i] = b[allR[t][i]];
		pii ttt = slv1(tmp, R);
		if (ttt.first <= ANS)
			B[++tr] = ttt;
	}
//	slv(A, tl);
//	slv(B, tr);
	sort(A + 1, A + tl + 1);
	sort(B + 1, B + tr + 1);
	int ans = 2e9;
	for (int i = 1, j = 0, mn = 2e9; i <= tl; i++) {
		while (j < tr && B[j + 1].first <= A[i].first)
			j++, mn = min(mn, B[j].second);
		if (j)
			ans = min(ans, max(A[i].first, A[i].second + mn));
	}
	for (int i = 1, j = 0, mn = 2e9; i <= tr; i++) {
		while (j < tl && A[j + 1].first <= B[i].first)
			j++, mn = min(mn, A[j].second);
		if (j)
			ans = min(ans, max(B[i].first, B[i].second + mn));
	}
	return ans;
}

int arr[N] = {0};



int chose[N] = {0};
bool vis[N] = {false};

int tot = 0;

clock_t stclock = 0;

void dfs(int x) {
	if (1.0 * (clock() - stclock) / CLOCKS_PER_SEC > 1) {
		cout << ANS;
		exit(0);
	}
	if (x > (n + 1) / 2) {
		++tot;
	//	if ((14 <= n && n <= 15 && tot % 5 != 0) || (n == 16 && tot % 15 != 0))
	//		return;
	
		for (int i = 1; i <= (n + 1) / 2; i++)	
			a[i] = arr[chose[i]];
		for (int i = 1, j = 0; i <= n; i++)
			if (!vis[i])
				b[++j] = arr[i];
		ANS = min(ANS, calc());
		return;
	}
	for (int i = chose[x - 1] + 1; i <= n; i++) {
		chose[x] = i;
		vis[i] = true;
		dfs(x + 1);
		vis[i] = false;
		if (x == 1)
			return;
	}
}

int main() {
	stclock = clock();
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &arr[i]);
	mt19937 myrand(time(0));
	shuffle(arr + 1, arr + n + 1, myrand);
	
	int L = (n + 1) / 2, R = n - L;
	for (int i = 1; i <= L; i++)
		p[i] = i;
	do {
		++totl;
		for (int i = 1; i <= L; i++)
			allL[totl][i] = p[i];
	} while (next_permutation(p + 1, p + L + 1));
	
	for (int i = 1; i <= R; i++)
		p[i] = i;
	do {
		++totr;
		for (int i = 1; i <= R; i++)
			allR[totr][i] = p[i];
	} while (next_permutation(p + 1, p + R + 1));
	
	dfs(1);
	cout << ANS << endl;
	return 0;
} 
/*
 6
 4 -4 5 -20 6 7
*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3800kb

input:

4
1 -1 1 1

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5804kb

input:

6
4 -4 5 -20 6 7

output:

9

result:

ok 1 number(s): "9"

Test #3:

score: 0
Accepted
time: 1000ms
memory: 11484kb

input:

16
74685 37459 -1863 43873 69565 11753 -27428 57636 -80511 13844 -20908 69580 4289 -99806 -75028 30372

output:

107512

result:

ok 1 number(s): "107512"

Test #4:

score: 0
Accepted
time: 1003ms
memory: 7820kb

input:

15
67994 74589 99849 97649 27926 26555 1194 -98123 4315 58602 67384 53308 59247 -17522 95188

output:

618155

result:

ok 1 number(s): "618155"

Test #5:

score: 0
Accepted
time: 396ms
memory: 4640kb

input:

14
-16144 -8970 -61906 -89752 -82770 52954 9044 85641 -78467 -71326 91206 -72168 -67481 58209

output:

91206

result:

ok 1 number(s): "91206"

Test #6:

score: 0
Accepted
time: 1004ms
memory: 9336kb

input:

15
88967 1252 94890 70842 94379 -43780 -23585 52697 93720 33707 -79062 93850 98030 68193 -96410

output:

547690

result:

ok 1 number(s): "547690"

Test #7:

score: 0
Accepted
time: 994ms
memory: 11268kb

input:

16
-95394 27873 82707 -8091 22839 -22353 77819 17786 -20965 -17390 21878 2116 44799 -4573 16174 7845

output:

153070

result:

ok 1 number(s): "153070"

Test #8:

score: 0
Accepted
time: 1004ms
memory: 11432kb

input:

16
73674 -66214 -39831 88784 42617 -75096 85579 1073 -55675 82743 -85078 -88198 12378 -14310 20005 33627

output:

88784

result:

ok 1 number(s): "88784"

Test #9:

score: 0
Accepted
time: 1004ms
memory: 11588kb

input:

16
-83517 -65495 8945 31495 -30343 94018 14500 -13614 68884 -45706 -18744 -67271 93093 -14098 -3592 -58773

output:

94018

result:

ok 1 number(s): "94018"

Test #10:

score: 0
Accepted
time: 1ms
memory: 3908kb

input:

6
-15003 -28170 -30377 81020 -44906 -21965

output:

81020

result:

ok 1 number(s): "81020"

Test #11:

score: 0
Accepted
time: 1004ms
memory: 10844kb

input:

16
-29848 4832 94117 -45241 1204 -99570 -10513 97070 48069 43198 -13260 41687 -57361 33422 -86646 -15135

output:

97070

result:

ok 1 number(s): "97070"

Test #12:

score: 0
Accepted
time: 1003ms
memory: 9276kb

input:

15
-40154 98402 72394 -18077 89858 -8243 82205 85533 18703 99891 64337 -40784 82754 62837 78715

output:

728371

result:

ok 1 number(s): "728371"

Test #13:

score: 0
Accepted
time: 314ms
memory: 6136kb

input:

14
66250 -35079 -57181 19720 81648 35074 32470 58509 53389 -57108 -98486 10518 50384 -93648

output:

86765

result:

ok 1 number(s): "86765"

Test #14:

score: 0
Accepted
time: 998ms
memory: 11812kb

input:

16
40899 86787 42827 46271 50611 5024 18935 -29778 -63775 50497 71624 66733 58611 11007 3100 95197

output:

554570

result:

ok 1 number(s): "554570"

Test #15:

score: 0
Accepted
time: 0ms
memory: 3924kb

input:

5
-45688 73098 -92315 33790 -13955

output:

73098

result:

ok 1 number(s): "73098"

Test #16:

score: 0
Accepted
time: 1ms
memory: 5980kb

input:

3
98693 1701 31884

output:

132278

result:

ok 1 number(s): "132278"

Test #17:

score: 0
Accepted
time: 1ms
memory: 5956kb

input:

1
28298

output:

28298

result:

ok 1 number(s): "28298"

Test #18:

score: 0
Accepted
time: 998ms
memory: 9328kb

input:

15
11823 66662 -54420 37824 22297 92212 69303 -43475 29895 90424 46778 59451 -6719 73011 3205

output:

498271

result:

ok 1 number(s): "498271"

Test #19:

score: 0
Accepted
time: 998ms
memory: 9584kb

input:

15
10336 -51879 68382 87402 -30237 -62771 80927 -15568 -6831 38917 98576 -18210 20823 66361 -11231

output:

274997

result:

ok 1 number(s): "274997"

Test #20:

score: 0
Accepted
time: 1003ms
memory: 10992kb

input:

16
-35603 19466 4413 -9913 48173 31103 35653 91725 -92984 73019 78100 38659 53651 53436 37700 17258

output:

443856

result:

ok 1 number(s): "443856"

Test #21:

score: 0
Accepted
time: 554ms
memory: 4632kb

input:

14
92942 63046 76091 19008 62272 27814 85894 -8202 28803 70386 29703 72309 -8672 -29761

output:

581633

result:

ok 1 number(s): "581633"

Test #22:

score: 0
Accepted
time: 1000ms
memory: 10836kb

input:

16
-50703 -66984 48586 -6141 -15903 -27332 57733 90767 46085 69464 68558 33327 89292 95868 62116 -72578

output:

422155

result:

ok 1 number(s): "422155"

Test #23:

score: 0
Accepted
time: 561ms
memory: 6384kb

input:

14
60071 97848 59818 1834 -73085 38212 2556 80145 -36394 77438 38246 71294 29559 64975

output:

512517

result:

ok 1 number(s): "512517"

Test #24:

score: 0
Accepted
time: 1005ms
memory: 9500kb

input:

15
-75702 61338 -62770 63958 31251 54962 -89816 -39497 37557 20958 9161 39979 9202 -41277 -6021

output:

63958

result:

ok 1 number(s): "63958"

Test #25:

score: 0
Accepted
time: 1004ms
memory: 11820kb

input:

16
75665 79752 -99064 -8136 66639 87625 -98947 52015 -19537 77222 -72932 -32254 -29250 54691 18405 467

output:

152361

result:

ok 1 number(s): "152361"

Test #26:

score: 0
Accepted
time: 1ms
memory: 5956kb

input:

7
96173 16477 -51289 -67315 22620 -44673 -61658

output:

96173

result:

ok 1 number(s): "96173"

Test #27:

score: 0
Accepted
time: 998ms
memory: 11464kb

input:

16
87522 82712 40975 41046 24283 -37439 48363 40457 16597 24556 -36680 -62798 27824 -70211 -43518 31243

output:

214932

result:

ok 1 number(s): "214932"

Test #28:

score: 0
Accepted
time: 1001ms
memory: 11492kb

input:

16
55572 71846 93230 -55096 97201 78206 75542 85807 58197 81578 79942 13793 8420 32911 78670 90793

output:

946612

result:

ok 1 number(s): "946612"

Test #29:

score: 0
Accepted
time: 999ms
memory: 9868kb

input:

15
-19411 -20105 -90206 18949 -39139 49737 34971 -72958 66306 75067 -39688 -52713 -62403 10814 -82166

output:

75067

result:

ok 1 number(s): "75067"

Test #30:

score: 0
Accepted
time: 1003ms
memory: 7752kb

input:

15
-50522 64266 -60252 91796 -12338 29457 -60883 27833 -56388 63831 -13936 85229 -10590 -53294 -30029

output:

91796

result:

ok 1 number(s): "91796"

Test #31:

score: 0
Accepted
time: 679ms
memory: 6284kb

input:

14
21864 3995 11329 -54641 3290 62434 84236 13172 -37803 15668 52521 -17267 5271 17005

output:

181074

result:

ok 1 number(s): "181074"

Test #32:

score: 0
Accepted
time: 1000ms
memory: 11300kb

input:

16
87906 33256 66708 92130 -93974 81186 81818 29420 90224 -21004 60067 23177 71078 503 67118 10202

output:

679815

result:

ok 1 number(s): "679815"

Test #33:

score: 0
Accepted
time: 749ms
memory: 4672kb

input:

14
-9800 -24965 -31025 92942 53446 9853 70196 37380 82648 -82472 -14731 49523 -38880 54296

output:

248411

result:

ok 1 number(s): "248411"

Test #34:

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

input:

10
75721 38266 -1028 -54009 64905 -90792 -71865 -21644 -35923 29982

output:

75721

result:

ok 1 number(s): "75721"

Test #35:

score: 0
Accepted
time: 998ms
memory: 9316kb

input:

15
46524 -5375 80174 -76289 54628 67732 91754 49901 -55289 3879 -73858 21824 -50736 46574 -12224

output:

189219

result:

ok 1 number(s): "189219"

Test #36:

score: 0
Accepted
time: 1005ms
memory: 11468kb

input:

16
24474 38900 76720 33678 43889 20692 -30474 54229 -57898 13963 63065 45575 81706 89743 49125 61757

output:

609144

result:

ok 1 number(s): "609144"

Test #37:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

7
93664 -68014 39364 -83881 -79054 67994 89332

output:

93664

result:

ok 1 number(s): "93664"

Test #38:

score: 0
Accepted
time: 0ms
memory: 5844kb

input:

3
31510 64114 20248

output:

115872

result:

ok 1 number(s): "115872"

Test #39:

score: 0
Accepted
time: 1005ms
memory: 10676kb

input:

16
-4771 -57558 53661 96749 -27899 96355 11037 48685 -79706 -67802 -16550 -54604 19804 -86097 20829 62158

output:

96749

result:

ok 1 number(s): "96749"

Test #40:

score: 0
Accepted
time: 593ms
memory: 6464kb

input:

14
23100 81349 81136 75654 41124 62771 86000 76734 87941 -79512 26553 -6096 -6293 22901

output:

573362

result:

ok 1 number(s): "573362"

Test #41:

score: 0
Accepted
time: 18ms
memory: 6024kb

input:

12
11580 36432 10078 98029 17015 31501 -53386 8894 81094 96306 43524 87779

output:

468846

result:

ok 1 number(s): "468846"

Test #42:

score: 0
Accepted
time: 1005ms
memory: 9692kb

input:

15
-14769 55659 -3652 57393 23410 34625 36078 -10607 85650 36106 63324 71631 -80028 -42496 27404

output:

339728

result:

ok 1 number(s): "339728"

Test #43:

score: 0
Accepted
time: 1ms
memory: 5844kb

input:

2
96032 -79560

output:

96032

result:

ok 1 number(s): "96032"

Test #44:

score: 0
Accepted
time: 398ms
memory: 6428kb

input:

14
-10406 -75637 20667 -60861 -24037 -27672 48255 -62603 -13300 74328 16467 -188 82137 46315

output:

82137

result:

ok 1 number(s): "82137"

Test #45:

score: 0
Accepted
time: 1002ms
memory: 9524kb

input:

15
-60537 -76493 -17309 -57622 90077 -50594 32123 -40848 91917 93303 -79448 22518 47771 18689 -79275

output:

93303

result:

ok 1 number(s): "93303"

Test #46:

score: 0
Accepted
time: 999ms
memory: 10848kb

input:

16
-86202 79572 12741 50730 48953 63238 59478 72696 88840 -93178 5160 42238 32761 99976 72985 62290

output:

612278

result:

ok 1 number(s): "612278"

Test #47:

score: 0
Accepted
time: 23ms
memory: 5872kb

input:

12
68729 -61967 -67621 36669 27426 87891 88900 80232 -20355 -55049 40490 13777

output:

239122

result:

ok 1 number(s): "239122"

Test #48:

score: 0
Accepted
time: 1005ms
memory: 8920kb

input:

15
-96152 -93482 -24627 -34909 88912 -94485 -71027 -96657 -3114 47662 62500 -58183 -36534 33970 -27670

output:

88912

result:

ok 1 number(s): "88912"

Test #49:

score: 0
Accepted
time: 412ms
memory: 6276kb

input:

14
34677 55187 276 87707 -62858 -17301 -45948 -92383 9018 59477 -37345 51760 -94996 5279

output:

87707

result:

ok 1 number(s): "87707"

Test #50:

score: 0
Accepted
time: 0ms
memory: 3724kb

input:

3
-90969 99356 73931

output:

99356

result:

ok 1 number(s): "99356"

Test #51:

score: 0
Accepted
time: 16ms
memory: 4028kb

input:

12
89758 51022 77845 83124 -7142 43742 53732 30888 -29314 62905 88852 90648

output:

636060

result:

ok 1 number(s): "636060"

Test #52:

score: 0
Accepted
time: 0ms
memory: 3912kb

input:

6
-38469 -16017 -28949 90823 -4651 1076

output:

90823

result:

ok 1 number(s): "90823"

Test #53:

score: 0
Accepted
time: 997ms
memory: 9672kb

input:

15
4398 -2335 4536 2432 -4096 -1305 -97526 3784 -4281 -4398 1014 3325 -260 4819 3265

output:

5449

result:

ok 1 number(s): "5449"

Test #54:

score: 0
Accepted
time: 1002ms
memory: 10652kb

input:

16
-4177 4477 1319 -3436 -93603 1364 -1147 2053 4048 2678 4795 2859 3742 788 883 3915

output:

12081

result:

ok 1 number(s): "12081"

Test #55:

score: 0
Accepted
time: 998ms
memory: 9472kb

input:

15
4715 1912 4265 2940 4117 -220 -4772 747 -1601 -81697 3858 1735 -2912 2727 2535

output:

10023

result:

ok 1 number(s): "10023"

Test #56:

score: 0
Accepted
time: 1004ms
memory: 9216kb

input:

15
2089 2924 968 -1612 -3816 4711 4946 -587 50 3058 -87243 4483 4078 2897 -1581

output:

11304

result:

ok 1 number(s): "11304"

Test #57:

score: 0
Accepted
time: 1003ms
memory: 11384kb

input:

16
-994 -701 2671 -4764 -96279 3247 -3235 3212 2803 1142 2352 -546 -3546 140 2361 1152

output:

3494

result:

ok 1 number(s): "3494"

Test #58:

score: 0
Accepted
time: 1001ms
memory: 11312kb

input:

16
1229 284 858 3769 2276 709 1931 -4315 444 4618 2820 1575 1201 4037 -97300 -3886

output:

8775

result:

ok 1 number(s): "8775"

Test #59:

score: 0
Accepted
time: 90ms
memory: 6156kb

input:

13
102 2495 -1120 4120 3167 -2070 4481 -91701 -2054 4915 -2093 -4917 2394

output:

4915

result:

ok 1 number(s): "4915"

Test #60:

score: -100
Wrong Answer
time: 1000ms
memory: 10720kb

input:

16
1757 2104 3996 2002 1711 -744 3259 -4587 1438 -2607 4681 -1242 4978 3346 2165 -88370

output:

11131

result:

wrong answer 1st numbers differ - expected: '11129', found: '11131'