UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196580#2855. 面积 squaretkswls1002644ms1512kbC++111.5kb2023-10-28 11:34:272023-10-28 12:06:47

answer

#include<bits/stdc++.h>
using namespace std;
int t, n, m, a[50005], ans;
int S(int p, int q, int w) {
	double e = (p + q + w) / 2.0;
	return	round(sqrt(e * (e - p) * (e - q) * (e - w)));
}
bitset<100005> b;
int readNum() {
	int x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return x * f;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	t = readNum();
	while (t--) {
		n = readNum();
		m = readNum();
		for (int i = 1; i <= n; i++) {
			a[i] = readNum();
		}
		if (n == m) {
			if (n <= 3) {
				cout << -1 << endl;
			} else {
				cout << 3 << endl;
			}
			continue;
		}
		sort(a + 1, a + n + 1);
		b.reset();
		bool flg = true;
		for (int i = 3; i <= n; i++) {
			if (a[i] < a[i - 1] + a[i - 2]) {
				flg = false;
				break;
			}
		}
		if (flg) {
			cout << -1 << endl;
			continue;
		}
		for (int i = 1; i <= n; i++) {
			b.set(a[i], 1);
		}
		bitset<100005> t;
		ans = 0x3f3f3f3f;
		for (int d = 1; d <= m / 2; d++) {
			int q = (b >> (d + 1))._Find_first();
			//			cout << q << ' ';
			if (q == -(1 << 31) - 1) continue;
			q += d + 1;
			t = b & (b >> d);
			t >>= (q + 1);
			if (t.count() == 0) continue;
			int p = t._Find_first();
			ans = min(ans, S(p + q + 1, p + q + d + 1, q ));
			//			cout << p << ' ' << q << ' ' << d << endl;
		}
		cout << ans << endl;
	}
	return 0;
}

详细

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

Test #1:

score: 10
Accepted
time: 10ms
memory: 1324kb

input:

15
1 10
10
2 10
10 9
4 34
32 7 30 17
10 169
106 134 125 169 151 82 135 50 44 63
10 146
96 25 128 41 ...

output:

-1
-1
103
380
343
21
86
88
452
39
54
384
17
1606
1964

result:

ok 15 lines

Test #2:

score: 10
Accepted
time: 10ms
memory: 1328kb

input:

13
9 40
12 39 4 18 11 27 33 17 15
8 177
144 172 37 159 21 147 41 10
3 186
1 6 167
4 64
62 57 23 1
7 ...

output:

18
177
-1
655
395
120
114
205
31
80
27
379
158

result:

ok 13 lines

Test #3:

score: 10
Accepted
time: 9ms
memory: 1320kb

input:

12
3 105
91 80 12
3 46
26 8 42
4 164
114 141 143 154
10 64
52 46 45 28 54 40 4 7 42 47
6 169
111 149...

output:

205
-1
7412
57
692
6
68
192
24
47
55
20

result:

ok 12 lines

Test #4:

score: 10
Accepted
time: 93ms
memory: 1324kb

input:

132
11 198
150 174 170 183 156 89 136 141 92 154 34
6 158
58 123 19 48 90 46
9 40
7 26 23 11 14 5 21...

output:

641
377
13
433
111
26
229
20
23
73
46
73
224
16
14
5
154
792
2592
87
49
255
110
256
-1
1028
135
344
...

result:

ok 132 lines

Test #5:

score: 10
Accepted
time: 91ms
memory: 1324kb

input:

120
11 143
62 52 137 6 29 11 27 63 15 39 31
4 170
108 146 157 66
10 85
5 34 81 27 22 50 76 35 82 24
...

output:

28
2837
51
74
219
20
118
66
249
280
-1
7371
19
89
4257
-1
396
560
546
266
104
346
-1
66
-1
57
114
42...

result:

ok 120 lines

Test #6:

score: 10
Accepted
time: 199ms
memory: 1328kb

input:

269
3 44
1 29 44
4 87
49 66 78 24
10 157
117 63 61 37 40 23 106 140 64 27
3 159
125 136 155
11 101
5...

output:

-1
476
175
8117
80
68
187
120
4472
1969
30
44
201
41
927
71
5
-1
4438
54
299
38
40
24
175
82
3
124
1...

result:

ok 269 lines

Test #7:

score: 10
Accepted
time: 5ms
memory: 1300kb

input:

79
741 741
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33...

output:

3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
-1
3
3
3
3...

result:

ok 79 lines

Test #8:

score: 10
Accepted
time: 749ms
memory: 1512kb

input:

1
50000 100000
1 20000 20002 20004 20005 20006 20008 20010 20011 20012 20014 20015 20017 20018 20020...

output:

2828551

result:

ok single line: '2828551'

Test #9:

score: 10
Accepted
time: 733ms
memory: 1444kb

input:

1
30000 100000
1 49000 49002 49004 49006 49008 49010 49011 49013 49015 49016 49018 49019 49021 49022...

output:

658704080

result:

ok single line: '658704080'

Test #10:

score: 10
Accepted
time: 745ms
memory: 1480kb

input:

1
40000 100000
2 10000 10002 10004 10006 10008 10010 10012 10014 10016 10018 10020 10022 10024 10026...

output:

77938

result:

ok single line: '77938'

Extra Test:

score: 0
Extra Test Passed