QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#410014 | #1945. Finding Polly | ohiostatescarlet | WA | 348ms | 6620kb | C++17 | 6.3kb | 2024-05-13 04:35:43 | 2024-05-13 04:35:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef __int128 I;
#define L I
bool segCol[12][12][12][12][12][12];
bool eq[12][12][12][12];
bool vald[12][12];
struct Li {
long long x1, x2, y1, y2;
pair<I,I> vec() {
return {x2-x1,y2-y1};
}
};
I igcd(I a, I b) {
if (b == 0) {
return a;
}
return igcd(b, a%b);
}
#define F long double
// struct F {
// I n, d;
// F() {}
// F(I n, I d) : n(n), d(d) {
// I g = igcd(d, n);
// this->d = d / g;
// this->n = n / g;
// if (this->d < 0) this->n *= -1, this->d *= -1;
// }
// bool operator==(F o) {
// return n == o.n && d == o.d;
// }
// F operator-(F o) {
// return {n * o.d - d * o.n, o.d * d};
// }
// F operator*(F o) {
// return {n * o.n, o.d * d};
// }
// };
struct Co {
bool valid;
F x, y;
Co() {}
Co(F x, F y) : x(x), y(y) {}
Co(Li a, Li b) {
auto [vax, vay] = a.vec();
auto [vbx, vby] = b.vec();
if (vax*vby-vay*vbx == 0) {
valid = false;
} else {
valid = true;
I x1 = a.x1, x2 = a.x2, x3 = b.x1, x4 = b.x2;
I y1 = a.y1, y2 = a.y2, y3 = b.y1, y4 = b.y2;
for (int i = 0; i < 2; i++) {
y = ((F)(y2-y1)*(y4*x3-x4*y3)-(y4-y3)*(y2*x1-x2*y1))/((F)(x3-x4)*(y2-y1)-(x1-x2)*(y4-y3));
swap(x, y); swap(x1, y1); swap(x2, y2); swap(x3, y3); swap(x4, y4);
}
}
}
bool operator==(Co&o) {
return x == o.x && y == o.y;
}
Co operator-(Co&o) {
return {x-o.x, y-o.y};
}
};
F cross(Co d1, Co d2) {
return d1.x * d2.y - d1.y * d2.x;
}
bool collides(Co p1, Co p2, Co q1, Co q2) {
for (int i = 0; i < 4; i++) {
Co dp = p2 - p1;
// cout << v.n << " " << v.d << endl;
F a = cross(dp, q1 - p1);
F b = cross(dp, q2 - p1);
if (a != 0 && b != 0 && ((a > 0) == (b > 0))) {
return false;
}
swap(p1, q2);
swap(p2, q1);
swap(q1, q2);
}
return true;
};
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
vector<Li> Z(n);
for (Li&l:Z) cin >> l.x1 >> l.y1 >> l.x2 >> l.y2;
vector<vector<Co>> collisions(n, vector<Co>(n));
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j) collisions[i][j] = Co(Z[i], Z[j]);
for (int i1 = 0; i1 < n-1; i1++) for (int i2 = 0; i2 < n; i2++) if (i2 != i1) for (int i3 = i1+1; i3 < n; i3++) if (i2 != i3)
for (int j1 = i1; j1 < n-1; j1++) for (int j2 = 0; j2 < n; j2++) if (j2 != j1) for (int j3 = j1+1; j3 < n; j3++) if (j2 != j3)
{
if (i1 != j1 || i2 != j2 || i3 != j3) {
segCol[i1][i2][i3][j1][j2][j3] =
segCol[i1][i2][i3][j3][j2][j1] =
segCol[i3][i2][i1][j1][j2][j3] =
segCol[i3][i2][i1][j3][j2][j1] =
segCol[j1][j2][j3][i1][i2][i3] =
segCol[j3][j2][j1][i1][i2][i3] =
segCol[j1][j2][j3][i3][i2][i1] =
segCol[j3][j2][j1][i3][i2][i1] = collides(
collisions[i1][i2], collisions[i2][i3],
collisions[j1][j2], collisions[j2][j3]
);
}
}
for (int i1 = 0; i1 < n-1; i1++) for (int i2 = i1+1; i2 < n; i2++) {
vald[i1][i2] = vald[i2][i1] = collisions[i1][i2].valid;
for (int j1 = i1; j1 < n-1; j1++) for (int j2 = j1+1; j2 < n; j2++) {
eq[i1][i2][j1][j2] =
eq[i1][i2][j2][j1] =
eq[i2][i1][j1][j2] =
eq[i2][i1][j2][j1] =
eq[j1][j2][i1][i2] =
eq[j2][j1][i1][i2] =
eq[j1][j2][i2][i1] =
eq[j2][j1][i2][i1] = (collisions[i1][i2] == collisions[j1][j2]);
}
}
vector<int> path;
queue<int> perm;
for (int i = 1; i < n; i++) perm.push(i);
path.push_back(0);
function<long long()> solve = [&]() {
if (!perm.size()) {
int p0 = path[0], p1 = path[1], pn1 = path[n-1], pn2 = path[n-2];
if (!vald[pn1][p0]) return 0ll;
if (eq[pn1][p0][p0][p1] || eq[pn1][p0][pn2][pn1]) return 0ll;
for (int i = 0; i < n-2; i++) {
if (i > 0 && segCol[pn1][p0][p1][path[i]][path[i+1]][path[i+2]]) return 0ll;
if (i < n-3 && segCol[pn2][pn1][p0][path[i]][path[i+1]][path[i+2]]) return 0ll;
}
// for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
// if ((i-j+n)%n > 2 && (j-i+n)%n > 2) {
// if (segCol[path[(i-1+n)%n]][path[i]][path[(i+1)%n]][path[(j-1+n)%n]][path[j]][path[(j+1)%n]]) {
// cout << path[(i-1+n)%n] << " " << path[i] << " " << path[(i+1)%n] << " " << path[(j-1+n)%n] << " " << path[j] << " " << path[(j+1)%n] << endl;
// cout << "!" << endl;
// return 1ll / 0;
// }
// }
// }
// for (int v : path) cout << v << " ";
// cout << '\n';
return 1ll;
} else {
long long res = 0;
for (int i = 0; i < perm.size(); i++) {
int u = perm.front(); perm.pop();
bool succ = true;
int pn1 = path[path.size()-1];
if (!vald[pn1][u]) {
succ = false;
} else if (path.size() >= 2) {
int pn2 = path[path.size()-2];
if (eq[pn2][pn1][pn1][u]) {
succ = false;
} else if (path.size() >= 3) {
for (int i = 0; i < path.size()-3; i++) {
if (segCol[pn2][pn1][u][path[i]][path[i+1]][path[i+2]]) {
succ = false;
break;
}
}
}
}
if (succ) {
path.push_back(u);
res += solve();
path.pop_back();
}
perm.push(u);
}
return res;
}
};
cout << solve() / 2 << "\n";
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 298ms
memory: 6548kb
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: 288ms
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: 348ms
memory: 6268kb
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: 1ms
memory: 4188kb
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: 7ms
memory: 5436kb
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: 44ms
memory: 6236kb
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: 140ms
memory: 6392kb
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: 3ms
memory: 4944kb
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: 1ms
memory: 5788kb
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: 6ms
memory: 5420kb
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:
54
result:
wrong answer 1st lines differ - expected: '33', found: '54'