QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408937#1945. Finding PollyohiostatescarletWA 2875ms6488kbC++175.1kb2024-05-11 12:18:142024-05-11 12:18:14

Judging History

This is the latest submission verdict.

  • [2024-05-11 12:18:14]
  • Judged
  • Verdict: WA
  • Time: 2875ms
  • Memory: 6488kb
  • [2024-05-11 12:18:14]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define L long long

bool segCol[12][12][12][12][12][12];
bool eq[12][12][12][12];
bool vald[12][12];

typedef __int128 I;

struct Li {
    L x1, x2, y1, y2;
    pair<L,L> vec() {
        return {x2-x1,y2-y1};
    }
};

struct F {
    L n, d;
    F() {}
    F(L n, L d) : n(n), d(d) {
        L g = gcd(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;
            L x1 = a.x1, x2 = a.x2, x3 = b.x1, x4 = b.x2;
            L y1 = a.y1, y2 = a.y2, y3 = b.y1, y4 = b.y2;
            for (int i = 0; i < 2; i++) {
                y = {(y2-y1)*(y4*x3-x4*y3)-(y4-y3)*(y2*x1-x2*y1), (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;
        F v = (cross(dp, q1 - p1) * cross(dp, q2 - p1));
        // cout << v.n << " " << v.d << endl;
        if (v.n > 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] = 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] = (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<L()> 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;
            }
            return 1ll;
        } else {
            L 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[pn1][u][pn2][pn1]) {
                        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: 0
Wrong Answer
time: 2875ms
memory: 6488kb

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:

3311431

result:

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