QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#455274 | #1945. Finding Polly | prostoegor239# | WA | 533ms | 6520kb | C++14 | 4.1kb | 2024-06-26 07:23:47 | 2024-06-26 07:23:47 |
Judging History
answer
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
ld eps = 1e-15L;
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) {
bool f1 = (A.x - Z.x) < eps;
bool f2 = (Z.x - B.x) < eps;
if (f1 ^ f2)
return false;
bool f3 = (A.y - Z.y) < eps;
bool f4 = (Z.y - B.y) < eps;
if (f3 ^ f4)
return false;
return true;
}
bool segment_intersec(point A, point B, point C, point D, line l, line k) {
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 abs(A.x - B.x) + abs(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[lines[k - 2]][lines[k - 1]][i])
f = 0;
if (k >= 1 && !is_inter[lines[k - 1]][i])
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]], all_lines[id[1]], all_lines[id[4]]);
}
}
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';
}
/*
5
0 0 1 0
1 0 3 1
3 1 0 4
0 4 -1 3
-1 3 0 0
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 462ms
memory: 6440kb
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: 453ms
memory: 6512kb
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: 533ms
memory: 6456kb
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: 6ms
memory: 5720kb
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: 6072kb
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: 125ms
memory: 6088kb
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: 265ms
memory: 6520kb
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: 21ms
memory: 5116kb
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: 5712kb
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: -100
Wrong Answer
time: 48ms
memory: 5492kb
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:
1571
result:
wrong answer 1st lines differ - expected: '33', found: '1571'