UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203131#3529. 新年的球棒侠smallstone1002592ms9364kbC++111.8kb2024-02-19 12:13:172024-02-19 12:33:15

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using L = __int128;
void print(L x) {
	if(x < 0) {
		putchar('-');
		print(-x);
		return;
	}
	if(x >= 10)
		print(x / 10);
	putchar(x % 10 + '0');
}
ll n, a[20], b[20], p[20], ans1, pre[1000010];
L f[1000010][2], x, y, z, z2, c = -4874204890000000000000;
#define abs(x) ((x) < 0 ? -(x) : (x))
vector<int> v[110];
void solve(ll mask) {
	if(f[mask][0] > c)
		return;
	for(ll j = 0 ; j < n ; j++)
		if((mask >> j) & 1ll) {
			solve(mask - (1ll << j));
			//cout << i << " " << (1ll << j) << "\n";
			z = f[mask - (1ll << j)][0];
			z2 = f[mask - (1ll << j)][1];
			x = a[j], y = b[j];
			f[mask][0] = max({f[mask][0], z * x + abs(z) * y, z2 * x + abs(z2) * y});
			f[mask][1] = min({f[mask][1], z * x + abs(z) * y, z2 * x + abs(z2) * y});
			//if(mask == 12)
				//print(f[mask]), cout << ' ', print(z), cout << ' ', print(x), cout << ' ', print(y), cout << " j:" << j << " " << "\n";
		}
	//printf("f[%lld] = ", mask); print(f[mask]); cout << "\n";
	return;
}
int main() {
	cin >> n;
	for(int i = 0 ; i < (1 << n) ; i++)
		f[i][0] = c, f[i][1] = -c;
	for(int i = 0 ; i < n ; i++) {
		cin >> a[i] >> b[i];
	}
	if(n <= 10) {
		ll ans1 = LONG_LONG_MIN;
		for(int i = 0 ; i < n ; i++)
			p[i] = i;
		do {
			ll cnt = 1;
			for(int i = 0 ; i < n ; i++)
				cnt = a[p[i]] * cnt + b[p[i]] * abs(cnt);
			ans1 = max(ans1, cnt);
		} while(next_permutation(p, p + n));
		cout << ans1;
		exit(0);
	}
	f[0][0] = f[0][1] = 1;
	//for(int i = 1 ; i < (1 << n) ; i++)
	//cout << i << " ", print(f[i]), cout << "\n";
	solve((1ll << n) - 1);
	print(max(f[(1ll << n) - 1][1], f[(1ll << n) - 1][0]));
	//cout << to_string(solve((1ll << n) - 1));
	return 0;
}
/*
10
10 6
11 5
-8 -2
14 9
15 9
-9 -14
-11 12
-12 8
4 -9
9 5

5
-9 -14
-11 12
-12 8
4 -9
9 5
*/

Details

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 40
Accepted

Test #1:

score: 40
Accepted
time: 69ms
memory: 1232kb

input:

10
6 -6
-8 3
8 15
7 -14
9 8
3 -10
-10 4
-10 13
-9 14
1 7

output:

162625095360

result:

ok single line: '162625095360'

Test #2:

score: 0
Accepted
time: 69ms
memory: 1236kb

input:

10
-4 12
8 6
-2 -13
-2 -7
6 -4
15 10
-14 8
4 -10
0 -6
12 -13

output:

349272000000

result:

ok single line: '349272000000'

Test #3:

score: 0
Accepted
time: 69ms
memory: 1232kb

input:

10
-3 -10
2 -8
-7 2
-10 15
-3 12
13 -9
-5 1
10 7
9 4
-9 11

output:

94809000000

result:

ok single line: '94809000000'

Test #4:

score: 0
Accepted
time: 69ms
memory: 1236kb

input:

10
7 -5
12 -7
10 -4
7 -5
1 -2
7 -6
-3 2
-10 -4
-3 -7
12 13

output:

10456992000

result:

ok single line: '10456992000'

Test #5:

score: 0
Accepted
time: 69ms
memory: 1236kb

input:

10
12 0
-11 1
-14 -11
-13 7
-9 -1
-5 -3
-6 1
-7 -1
-4 3
-4 3

output:

-1036800

result:

ok single line: '-1036800'

Test #6:

score: 0
Accepted
time: 70ms
memory: 1232kb

input:

10
4 2
9 -12
-2 11
8 -6
-8 6
-14 5
10 2
-2 5
-15 11
5 -1

output:

4032758016

result:

ok single line: '4032758016'

Test #7:

score: 0
Accepted
time: 72ms
memory: 1236kb

input:

10
-12 -9
12 1
-4 15
-13 -11
-13 -12
-12 -6
-13 3
-6 14
-10 -14
-7 9

output:

1328431104000

result:

ok single line: '1328431104000'

Test #8:

score: 0
Accepted
time: 69ms
memory: 1236kb

input:

10
-14 -2
-9 -6
14 12
14 4
-14 13
2 -14
14 8
9 -5
7 -5
-2 -3

output:

672518246400

result:

ok single line: '672518246400'

Test #9:

score: 0
Accepted
time: 69ms
memory: 1232kb

input:

10
-12 -5
9 15
-12 2
-14 9
4 -11
7 7
9 -15
6 -5
5 -6
-2 -8

output:

801183398400

result:

ok single line: '801183398400'

Test #10:

score: 0
Accepted
time: 69ms
memory: 1232kb

input:

10
9 -6
-14 -10
-4 -3
-2 1
-4 -2
-7 3
-10 5
-7 -6
-6 4
-3 1

output:

-1920

result:

ok single line: '-1920'

Test #11:

score: 0
Accepted
time: 69ms
memory: 1232kb

input:

10
7 8
7 9
-1 -7
1 -4
8 -4
14 0
-4 -6
0 0
-9 -7
-14 3

output:

0

result:

ok single line: '0'

Test #12:

score: 0
Accepted
time: 69ms
memory: 1236kb

input:

10
-9 -12
-5 7
7 -11
10 6
-11 -4
8 -13
-9 5
-10 0
1 12
3 -8

output:

387272793600

result:

ok single line: '387272793600'

Test #13:

score: 0
Accepted
time: 71ms
memory: 1236kb

input:

10
9 12
-7 -3
6 12
-5 -15
11 12
14 -4
-7 15
-6 11
7 13
15 -13

output:

6555136896000

result:

ok single line: '6555136896000'

Test #14:

score: 0
Accepted
time: 69ms
memory: 1232kb

input:

10
-11 -6
6 4
-5 7
-9 0
-4 14
3 -1
-8 3
3 5
-2 2
8 9

output:

3595622400

result:

ok single line: '3595622400'

Test #15:

score: 0
Accepted
time: 67ms
memory: 1236kb

input:

10
4 0
-14 -9
-13 -9
-10 -5
-10 3
-12 -6
-10 -3
-7 0
-5 1
-5 3

output:

-12230400

result:

ok single line: '-12230400'

Subtask #2:

score: 60
Accepted

Test #16:

score: 60
Accepted
time: 93ms
memory: 9364kb

input:

18
14 13
-9 2
-7 5
5 5
-15 -13
-3 6
-1 7
-7 9
8 15
-6 8
5 0
1 -14
0 6
6 -2
10 -9
-2 -11
1 -9
1 0

output:

1452282040103731200

result:

ok single line: '1452282040103731200'

Test #17:

score: 0
Accepted
time: 92ms
memory: 9364kb

input:

18
-2 -6
-3 -15
1 11
12 3
-7 -5
6 12
-2 8
-10 -4
-10 15
4 -11
-9 3
-11 14
-5 -1
10 4
-10 13
2 15
4 -...

output:

527104517022720000000

result:

ok single line: '527104517022720000000'

Test #18:

score: 0
Accepted
time: 93ms
memory: 9364kb

input:

18
3 -5
15 13
-8 -10
1 12
-15 -15
-2 -3
-4 -1
-15 -12
-12 -11
12 -9
-9 -4
-10 7
-9 5
8 -14
-11 1
-2 ...

output:

420945667294344192000

result:

ok single line: '420945667294344192000'

Test #19:

score: 0
Accepted
time: 105ms
memory: 9364kb

input:

18
-12 4
-5 -11
-4 12
8 15
9 -3
5 -11
4 -11
-10 -5
-3 -6
7 8
2 -12
10 -2
12 -12
-6 3
-5 9
-14 -15
-5...

output:

636002781836083200000

result:

ok single line: '636002781836083200000'

Test #20:

score: 0
Accepted
time: 95ms
memory: 9364kb

input:

18
13 10
-8 -2
-12 -3
-8 4
-6 4
-13 -2
-6 5
-1 0
-13 -8
-14 -9
-10 -1
-4 -1
-2 0
-5 4
-2 1
-7 -5
-11...

output:

-384912000

result:

ok single line: '-384912000'

Test #21:

score: 0
Accepted
time: 96ms
memory: 9364kb

input:

18
12 2
-2 -3
13 -3
4 10
1 7
-15 -14
-12 -9
-8 9
-7 -5
-3 -13
-9 5
-11 -8
5 -7
8 -14
9 -12
-14 7
-11...

output:

904917382090444800000

result:

ok single line: '904917382090444800000'

Test #22:

score: 0
Accepted
time: 101ms
memory: 9360kb

input:

18
14 -3
-11 12
6 -4
9 -15
5 -3
-5 -3
-14 -9
8 -5
15 2
-6 -14
-6 9
-7 10
5 9
2 11
-5 -4
-12 -2
0 -10...

output:

280520653187174400000

result:

ok single line: '280520653187174400000'

Test #23:

score: 0
Accepted
time: 107ms
memory: 9360kb

input:

18
-12 -11
3 -1
-15 -1
-8 4
0 -14
7 11
0 -1
-10 13
-5 -8
14 -9
-9 8
13 -7
15 -11
11 10
4 -6
4 -13
1 ...

output:

91776757015996416000

result:

ok single line: '91776757015996416000'

Test #24:

score: 0
Accepted
time: 110ms
memory: 9360kb

input:

18
-14 12
6 -5
13 8
5 6
15 0
8 -9
-5 0
-12 11
-1 4
-13 -1
-2 -11
-4 11
-11 -2
10 -1
-8 -11
-6 13
3 0...

output:

114675650041262310000

result:

ok single line: '114675650041262310000'

Test #25:

score: 0
Accepted
time: 110ms
memory: 9364kb

input:

18
11 5
-1 0
-13 2
-12 -9
-2 0
-6 5
-4 -3
-2 -1
-3 0
-11 0
-10 -9
-1 0
-2 1
-5 -2
-1 0
-10 -4
-9 3
-...

output:

-2822688

result:

ok single line: '-2822688'

Test #26:

score: 0
Accepted
time: 111ms
memory: 9364kb

input:

18
-2 -8
13 -13
-10 -15
4 2
-6 -4
-13 5
-11 -8
-1 11
-11 11
10 -6
-14 -15
0 8
-15 14
-7 -7
-13 -5
2 ...

output:

2491391834690863104000

result:

ok single line: '2491391834690863104000'

Test #27:

score: 0
Accepted
time: 117ms
memory: 9364kb

input:

18
-14 -5
4 -1
12 -7
0 10
-3 -10
-11 -2
6 6
12 -12
12 14
5 -12
-11 -1
-6 -1
5 3
-15 -9
-14 14
0 -5
-...

output:

116903080407859200000

result:

ok single line: '116903080407859200000'

Test #28:

score: 0
Accepted
time: 114ms
memory: 9360kb

input:

18
-3 -15
-11 -10
15 6
0 15
14 14
2 4
14 -15
-2 -4
3 -2
10 11
15 12
-6 -7
10 -11
-12 1
3 1
6 -6
-9 -...

output:

101605583404807372800

result:

ok single line: '101605583404807372800'

Test #29:

score: 0
Accepted
time: 112ms
memory: 9364kb

input:

18
-8 3
-13 12
-12 9
-5 -8
-10 0
-4 9
2 6
5 -13
7 12
13 7
-15 -6
14 13
-12 -10
-4 -14
-10 1
-2 -5
8 ...

output:

1625048846318177280000

result:

ok single line: '1625048846318177280000'

Test #30:

score: 0
Accepted
time: 97ms
memory: 9360kb

input:

18
4 2
-13 12
-13 -9
-1 0
-2 -1
-2 1
-8 2
-8 -3
-9 2
-9 8
-2 1
-13 -10
-4 1
-2 1
-1 0
-2 0
-8 3
-3 2

output:

-237600

result:

ok single line: '-237600'

Extra Test:

score: 0
Extra Test Passed