QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#455271#1945. Finding Pollyprostoegor239#WA 508ms6620kbC++144.0kb2024-06-26 04:43:542024-06-26 04:43:54

Judging History

This is the latest submission verdict.

  • [2024-06-26 04:43:54]
  • Judged
  • Verdict: WA
  • Time: 508ms
  • Memory: 6620kb
  • [2024-06-26 04:43:54]
  • Submitted

answer

#include <iostream>
#include <vector>
#include <math.h>

using namespace std;
using ll = long long;
using ld = long double;

ld eps = 1e-5;

const int N = 12;



struct point {
	ld x;
	ld y;
	point() {}

	point(ld x0, ld y0) {
		x = x0;
		y = y0;
	}

};


struct line {
	ld A;
	ld B;
	ld C;
	line() {}

	line(ld A, ld B, ld C) {
		this->A = A;
		this->B = B;
		this->C = C;
	}

	line(point D, point E) {
		this->A = D.y - E.y;
		this->B = E.x - D.x;
		this->C = -(A * D.x + B * D.y);
	}

};

bool is_intersect(line l, line k) {
	return abs(l.A * k.B - l.B * k.A) > eps;
}


point intersect(line l, line k) {
	ld q = l.A * k.B - l.B * k.A;
	ld y = (l.C * k.A - l.A * k.C) / q;
	ld x = (l.B * k.C - l.C * k.B) / q;
	return point(x, y);
}


point inter[N][N];
bool is_inter[N][N];
bool mem[N][N][N][N][N][N];
bool lol[N][N][N];


bool is_on_segment(point A, point B, point Z) {
	if ((A.x - Z.x) * (Z.x - B.x) < -eps)
		return false;

	if ((A.y - Z.y) * (Z.y - B.y) < -eps)
		return false;
	return true;

}


bool segment_intersec(point A, point B, point C, point D) {
	line l = line(A, B);
	line k = line(C, D);
	if (!is_intersect(l, k))
		return false;
	point E = intersect(l, k);
	return (is_on_segment(A, B, E) && is_on_segment(C, D, E));
}


ld dist(point A, point B) {
	return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
}


line all_lines[N];
int lines[N];
int lines_len = 0;
int points_len = 0;
point points[N];

ll kek(ll mask, int n) {
	if (mask == 0) {

		if (!lol[lines[n - 2]][lines[n - 1]][lines[0]])
			return 0;

		for (int i = 0; i + 2 <= n - 2; i++)
			if (mem[lines[n - 2]][lines[n - 1]][lines[0]][lines[i]]
				[lines[i + 1]][lines[i + 2]])
				return 0;

		if (!lol[lines[n - 1]][lines[0]][lines[1]])
			return 0;

		for (int i = 1; i + 2 <= n - 1; i++)
			if (mem[lines[n - 1]][lines[0]][lines[1]][lines[i]]
				[lines[i + 1]][lines[i + 2]])
				return 0;

		return 1;

		
	}
	else {
		ll sum = 0;
		int k = lines_len;
		point A(-1, -1);
		
		for (int i = 0; i < n; i++) {
			if ((1 << i) & mask) {
				bool f = 1;
				if (k >= 2 && !lol[i][lines[k - 1]][lines[k - 2]])
					f = 0;

				for (int j = 0; j <= k - 4 && f; j++) {
					if (mem[lines[j]][lines[j + 1]][lines[j + 2]][lines[k - 2]][lines[k - 1]][i])
						f = 0;
				}
				if (f) {
					lines[lines_len] = i;
					lines_len++;
					
					sum += kek(mask - (1 << i), n);
					lines_len--;
				}
			}
		}
		
		return sum;
	}
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		point A = point(a, b);
		point B = point(c, d);
		line l = line(A, B);
		all_lines[i] = l;
	}
	

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i != j) {
				is_inter[i][j] = is_intersect(all_lines[i], all_lines[j]);
				if (is_inter[i][j])
					inter[i][j] = intersect(all_lines[i], all_lines[j]);
			}

		}
	}

	for (int i = 0; i < n * n * n * n * n * n; i++) {
		vector<int> id(6);
		int cur = i;
		for (int j = 0; j < 6; j++) {
			id[j] = cur % n;
			cur /= n;
		}

		if (!is_inter[id[0]][id[1]] || !is_inter[id[2]][id[1]]
			|| !is_inter[id[3]][id[4]] || !is_inter[id[4]][id[5]])
			mem[id[0]][id[1]][id[2]][id[3]][id[4]][id[5]] = 1;
		else {
			mem[id[0]][id[1]][id[2]][id[3]][id[4]][id[5]] =
				segment_intersec(inter[id[0]][id[1]], inter[id[2]][id[1]],
					inter[id[3]][id[4]], inter[id[4]][id[5]]);
		}
	}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < n; k++) {
				if (!is_inter[i][j] || !is_inter[j][k])
					lol[i][j][k] = 0;
				else
					lol[i][j][k] = (dist(inter[i][j], inter[j][k]) > eps);
			}

	lines[0] = 0;
	lines_len = 1;

	ll mask = (1 << n) - 1 - 1;
	ll ans = kek(mask, n);
	cout << ans  / 2<< '\n';
}

/*
6
0 0 1 0
1 0 0 1
0 1 0 0
0 0 -1 -1
-1 -1 -2 -1
-2 -1 0 0
*/

详细

Test #1:

score: 100
Accepted
time: 447ms
memory: 6528kb

input:

12
1754 -1894 1131 163
-1361 350 1392 -1473
1672 -1863 -634 1706
-1869 498 -432 700
355 1737 -1052 -771
590 1273 -158 778
-1599 1914 -1543 -1839
191 995 -1589 -1387
-1126 -30 854 -1504
-1127 -794 -234 523
-653 -1719 903 -1828
-325 -1165 1958 -1015

output:

154903

result:

ok single line: '154903'

Test #2:

score: 0
Accepted
time: 441ms
memory: 6620kb

input:

12
-269 1562 1704 -519
863 -434 1536 1614
-1620 -1015 -153 56
-429 -806 -671 -720
-1234 1163 1228 58
1067 247 -243 181
1561 1598 494 1380
-1416 -376 -755 -1550
87 -1902 -44 -294
-759 646 -780 -1396
-765 -1066 -1124 277
-1751 -1406 -737 1614

output:

110265

result:

ok single line: '110265'

Test #3:

score: 0
Accepted
time: 508ms
memory: 6548kb

input:

12
1056 76 -284 1291
371 935 392 -503
1968 -1654 46 -548
-1890 1887 984 1067
-491 3 1659 246
413 211 32 -110
-693 -147 406 -1104
-496 -435 -35 -84
-1542 -1183 1331 1722
-327 -1994 -1525 821
915 1175 1177 -1263
-547 -1872 -1606 -1574

output:

136696

result:

ok single line: '136696'

Test #4:

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

input:

7
133 -774 -212 650
664 -137 -132 50
-283 -436 -211 335
-412 37 827 -279
-184 -229 -788 -950
-573 139 -971 488
-357 307 -258 14

output:

73

result:

ok single line: '73'

Test #5:

score: 0
Accepted
time: 39ms
memory: 5644kb

input:

10
981 1743 1818 833
1818 833 1961 -394
1961 -394 1354 -1472
1354 -1472 231 -1987
231 -1987 -981 -1743
-981 -1743 -1818 -833
-1818 -833 -1961 394
-1961 394 -1354 1472
-1354 1472 -231 1987
-231 1987 981 1743

output:

3138

result:

ok single line: '3138'

Test #6:

score: 0
Accepted
time: 120ms
memory: 6356kb

input:

11
363 1967 1369 1458
1369 1458 1940 487
1940 487 1895 -639
1895 -639 1249 -1562
1249 -1562 206 -1989
206 -1989 -902 -1785
-902 -1785 -1724 -1014
-1724 -1014 -1998 79
-1998 79 -1638 1147
-1638 1147 -758 1851
-758 1851 363 1967

output:

27490

result:

ok single line: '27490'

Test #7:

score: 0
Accepted
time: 256ms
memory: 6472kb

input:

12
1201 1599 1840 784
1840 784 1985 -241
1985 -241 1599 -1201
1599 -1201 784 -1840
784 -1840 -241 -1985
-241 -1985 -1201 -1599
-1201 -1599 -1840 -784
-1840 -784 -1985 241
-1985 241 -1599 1201
-1599 1201 -784 1840
-784 1840 241 1985
241 1985 1201 1599

output:

71780

result:

ok single line: '71780'

Test #8:

score: 0
Accepted
time: 25ms
memory: 6080kb

input:

9
6 2000 1290 1528
1290 1528 1971 341
1971 341 1729 -1005
1729 -1005 678 -1882
678 -1882 -690 -1877
-690 -1877 -1735 -995
-1735 -995 -1969 353
-1969 353 -1281 1536
-1281 1536 6 2000

output:

1360

result:

ok single line: '1360'

Test #9:

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

input:

6
201 980 980 -201
201 980 -201 -980
201 980 -980 201
980 -201 -201 -980
980 -201 -980 201
-201 -980 -980 201

output:

0

result:

ok single line: '0'

Test #10:

score: 0
Accepted
time: 40ms
memory: 5596kb

input:

10
803 596 815 -580
803 596 -300 -954
803 596 -1000 -10
803 596 -319 948
815 -580 -300 -954
815 -580 -1000 -10
815 -580 -319 948
-300 -954 -1000 -10
-300 -954 -319 948
-1000 -10 -319 948

output:

33

result:

ok single line: '33'

Test #11:

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

input:

4
0 0 0 1
0 1 1 1
1 1 1 0
1 0 0 0

output:

1

result:

ok single line: '1'

Test #12:

score: 0
Accepted
time: 25ms
memory: 5520kb

input:

10
0 0 0 1
1 0 1 1
2 0 2 1
0 0 1 0
0 1 1 1
0 2 1 2
0 3 1 3
0 4 1 4
0 5 1 5
0 6 1 6

output:

0

result:

ok single line: '0'

Test #13:

score: 0
Accepted
time: 24ms
memory: 5664kb

input:

10
0 0 0 1
1 0 1 1
2 0 2 1
3 0 3 1
0 0 1 0
0 1 1 1
0 2 1 2
0 3 1 3
0 4 1 4
0 5 1 5

output:

0

result:

ok single line: '0'

Test #14:

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

input:

10
0 0 0 1
1 0 1 1
2 0 2 1
3 0 3 1
4 0 4 1
0 0 1 0
0 1 1 1
0 2 1 2
0 3 1 3
0 4 1 4

output:

240

result:

ok single line: '240'

Test #15:

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

input:

3
416 909 580 -815
580 -815 -996 -95
-996 -95 416 909

output:

1

result:

ok single line: '1'

Test #16:

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

input:

4
287 958 958 -287
958 -287 -287 -958
-287 -958 -958 287
-958 287 287 958

output:

1

result:

ok single line: '1'

Test #17:

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

input:

5
271 963 999 40
999 40 347 -938
347 -938 -785 -620
-785 -620 -832 555
-832 555 271 963

output:

6

result:

ok single line: '6'

Test #18:

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

input:

6
210 978 952 307
952 307 741 -671
741 -671 -210 -978
-210 -978 -952 -307
-952 -307 -741 671
-741 671 210 978

output:

10

result:

ok single line: '10'

Test #19:

score: 0
Accepted
time: 5ms
memory: 5864kb

input:

7
784 621 974 -226
974 -226 431 -902
431 -902 -437 -900
-437 -900 -976 -219
-976 -219 -780 626
-780 626 3 1000
3 1000 784 621

output:

85

result:

ok single line: '85'

Test #20:

score: 0
Accepted
time: 9ms
memory: 4684kb

input:

8
765 644 996 -85
996 -85 644 -765
644 -765 -85 -996
-85 -996 -765 -644
-765 -644 -996 85
-996 85 -644 765
-644 765 85 996
85 996 765 644

output:

167

result:

ok single line: '167'

Test #21:

score: 0
Accepted
time: 25ms
memory: 5092kb

input:

9
511 860 944 330
944 330 935 -354
935 -354 489 -872
489 -872 -186 -983
-186 -983 -774 -633
-774 -633 -1000 13
-1000 13 -758 652
-758 652 -161 987
-161 987 511 860

output:

1360

result:

ok single line: '1360'

Test #22:

score: 0
Accepted
time: 39ms
memory: 5732kb

input:

10
583 813 949 315
949 315 953 -303
953 -303 593 -805
593 -805 6 -1000
6 -1000 -583 -813
-583 -813 -949 -315
-949 -315 -953 303
-953 303 -593 805
-593 805 -6 1000
-6 1000 583 813

output:

3138

result:

ok single line: '3138'

Test #23:

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

input:

6
275 961 961 -275
275 961 -275 -961
275 961 -961 275
961 -275 -275 -961
961 -275 -961 275
-275 -961 -961 275

output:

0

result:

ok single line: '0'

Test #24:

score: 0
Accepted
time: 43ms
memory: 6480kb

input:

10
538 843 968 -251
538 843 60 -998
538 843 -931 -366
538 843 -636 772
968 -251 60 -998
968 -251 -931 -366
968 -251 -636 772
60 -998 -931 -366
60 -998 -636 772
-931 -366 -636 772

output:

33

result:

ok single line: '33'

Test #25:

score: -100
Wrong Answer
time: 0ms
memory: 3772kb

input:

3
-1038 -1453 1531 1687
1513 -565 -1222 86
-1459 652 1424 -1051

output:

0

result:

wrong answer 1st lines differ - expected: '1', found: '0'