QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#128405#6570. Who Watches the Watchmen?installb#WA 1ms9800kbC++144.9kb2023-07-20 22:35:532023-07-20 22:35:56

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-20 22:35:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9800kb
  • [2023-07-20 22:35:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 2005;
const int M = 1000005;

struct point{
    int x,y,z; int id;
    point (int _x = 0,int _y = 0,int _z = 0) : x(_x), y(_y), z(_z) {}
}p[N],d[N],sp[N];

bool cmp(point p1,point p2){
    if(p1.x != p2.x) return p1.x < p2.x;
    if(p1.y != p2.y) return p1.y < p2.y;
    return p1.z < p2.z;
}

point simpl(const point &p){
    int x = abs(__gcd(p.x,__gcd(p.y,p.z)));
    return point(p.x / x,p.y / x,p.z / x);
}

point operator - (const point &p1,const point &p2){
    return point(p1.x - p2.x,p1.y - p2.y,p1.z - p2.z);
}

point operator + (const point &p1,const point &p2){
    return point(p1.x + p2.x,p1.y + p2.y,p1.z + p2.z);
}

point det(const point &p1,const point &p2){
    return point(p1.y * p2.z - p1.z * p2.y,p1.z * p2.x - p1.x * p2.z,p1.x * p2.y - p1.y * p2.x);
}

ll dot(const point &p1,const point &p2){
    return 1ll * p1.x * p2.x + 1ll * p1.y * p2.y + 1ll * p1.z * p2.z;
}

int len(const point &p){
    return abs(p.x) + abs(p.y) + abs(p.z);
}

bool operator == (const point &p1,const point &p2){
    return p1.x == p2.x && p1.y == p2.y && p1.z == p2.z;
}

bool operator != (const point &p1,const point &p2){
    return p1.x != p2.x || p1.y != p2.y || p1.z != p2.z;
}

bool eq(const point &p1,const point &p2){
    return simpl(p1) == simpl(p2) || simpl(p1) == point(0,0,0) - simpl(p2);
}

void input(point &p){
    cin >> p.x >> p.y >> p.z;
}

int ec = 1,to[M << 1],nxt[M << 1],cap[M << 1],w[M << 1];
int hed[N];
void add_edge(int f,int t,int c,int d){
    ++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec; cap[ec] = c; w[ec] = d;
    ++ ec; to[ec] = f; nxt[ec] = hed[t]; hed[t] = ec; cap[ec] = 0; w[ec] = -d;
}

int dis[N],inq[N],flw[N],pre[N],prv[N];

const int INF = 0x3f3f3f3f;

int spfa(int s,int t){
    for(int i = 1;i <= t;i ++){
        dis[i] = INF; inq[i] = 0; flw[i] = 0;
    }
    prv[t] = -1;
    queue <int> q;
    q.push(s); inq[s] = 1; dis[s] = 0; flw[s] = INF;
    while(!q.empty()){
        int u = q.front(); q.pop();
        inq[u] = 0;
        for(int i = hed[u];i;i = nxt[i]){
            int v = to[i];
            if(dis[v] > dis[u] + w[i] && cap[i]){
                dis[v] = dis[u] + w[i];
                prv[v] = u;
                pre[v] = i;
                flw[v] = min(flw[u],cap[i]);
                if(!inq[v]){
                    q.push(v);
                    inq[v] = 1;
                }
            }
        }
    }
    return prv[t] != -1;
}

int mcf = 0,mxf = 0;
void mcmf(int s,int t){
    while(spfa(s,t)){
        mxf += flw[t];
        mcf += flw[t] * dis[t];
        int now = t;
        while(now != s){
            cap[pre[now]] -= flw[t];
            cap[pre[now] ^ 1] += flw[t];
            now = prv[now];
        }
    }
}

int n;

void solve(){
    cin >> n;
    for(int i = 1;i <= n;i ++){
        input(p[i]);
        input(d[i]);
        p[i].id = i;
    }

    int S = n + n + 1;
    int T = S + 1;
    for(int i = 1;i <= n;i ++){
        point di = simpl(d[i]);
        for(int j = 1;j <= n;j ++) if(j != i) sp[j] = simpl(p[j] - p[i]);
        for(int j = 1;j <= n;j ++){
            if(i == j) continue;
            if(sp[j] == di){
                int fl = 0;
                for(int k = 1;k <= n;k ++){
                    if(k == i || k == j) continue;
                    if(sp[k] == di && len(p[k] - p[i]) < len(p[j] - p[i])){
                        fl = 1; break;
                    }
                }
                if(!fl) add_edge(i,j + n,1,0);
            }
            else add_edge(i,j + n,1,1);
        }
        add_edge(S,i,1,0);
        add_edge(i + n,T,1,0);
    }
    mcmf(S,T);
    if(mxf == n){
        cout << mcf << '\n';
        return;
    }

    int del = 0;
    for(int id = 1;id <= n;id ++){
        vector <point> G;
        for(int i = 1;i <= n;i ++){
            if(i == id) continue;
            G.push_back(p[i]);
        }
        sort(G.begin(),G.end(),cmp);
        point b = G[0];
        point e = G.back();
        // id -> b -> e
        int cur = 0;
        if(dot(det(e - b,d[id]),d[e.id]) == 0 && !eq(d[e.id],e - b) && !eq(d[id],e - b)) cur = 2;
        if(!eq(d[e.id],e - b) || !eq(d[id],e - b)) cur = 1;
        for(int i = 0;i + 1 < G.size();i ++){
            if(simpl(d[G[i].id]) == simpl(G[i + 1].id - G[i].id)) cur ++;
        }
        del = max(del,cur);

        // id -> e -> b
        cur = 0;
        if(dot(det(e - b,d[id]),d[e.id]) == 0 && !eq(d[e.id],e - b) && !eq(d[id],e - b)) cur = 2;
        if(!eq(d[e.id],e - b) || !eq(d[id],e - b)) cur = 1;
        for(int i = G.size() - 1;i >= 1;i --){
            if(simpl(d[G[i].id]) == simpl(G[i - 1].id - G[i].id)) cur ++;
        }
        del = max(del,cur);
    }
    cout << 1000 + n - del << '\n';
}

int main(){
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 9800kb

input:

7
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 1 0 0
5 0 0 1 0 0
6 0 0 -1 0 0

output:

1

result:

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