QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#601486#9424. Stop the Castle 2kevinshan#WA 215ms40328kbC++145.8kb2024-09-30 01:33:332024-09-30 01:33:33

Judging History

This is the latest submission verdict.

  • [2024-09-30 01:33:33]
  • Judged
  • Verdict: WA
  • Time: 215ms
  • Memory: 40328kb
  • [2024-09-30 01:33:33]
  • Submitted

answer

#include<bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;

const int N =500010,M=500010;


int tmpx[500100],tmpy[500010],tmpxs,tmpys,Chengs,Cshus;
bool used[500010],solvedzuo[500100],solvedyou[500010];
int x[500010],y[500010],n,m,k,zuo[500010],you[500010],fxb[500010];
vector<int> heng[200010],shu[200010];
bool Solvablezuo[500010],Solvableyou[500010];
int Solvables;

map<pair<int,int>,int> Cheng;
map<pair<int,int>,int> Cshu;

namespace Flow{
    int tot=1,fi[N],a[M],c[M],ne[M];
    void Add(int x,int y,int z){
        a[++tot]=y;ne[tot]=fi[x];fi[x]=tot;c[tot]=z;
    }
    int Adde(int x,int y,int z){
        Add(x,y,z),Add(y,x,0);
        return tot;
    }
    int cur[N],de[N];
    queue<int> q;
    bool Bfs(int s,int t){
        //memset(de,0,sizeof(de));
        FOR(i,0,Chengs + Cshus+10) de[i]=0;
        de[s]=1;
        q.push(s);
        while (!q.empty()){
            int u=q.front();q.pop();
            for (int i=fi[u];i;i=ne[i])
                if (c[i] && !de[a[i]]) de[a[i]]=de[u]+1,q.push(a[i]);
        }
        return de[t];
    }
    int Dfs(int x,int flow,int t){
        if (x==t) return flow;
        int tmp,s=0;
        for (int &i=cur[x];i;i=ne[i])
            if (c[i] && de[x]+1 == de[a[i]] && (tmp=Dfs(a[i],min(flow,c[i]),t))){
                c[i]-=tmp;
                c[i^1]+=tmp;
                flow-=tmp;
                s+=tmp;
                if (!flow) return s;
            }
        return s;
    }
    int Solve(int s,int t){
        int maxflow=0;
        while (Bfs(s,t)) memcpy(cur,fi,sizeof fi),maxflow+=Dfs(s,1e9,t);
        return maxflow;
    }
};


void doit(){
    scanf("%d%d%d",&n,&m,&k);
    int tmpxs=0,tmpys=0;
    FOR(i,1,n){
        scanf("%d%d",&x[i],&y[i]);
        tmpx[++tmpxs]=x[i];
        tmpy[++tmpys]=y[i];
    }
    sort(tmpx+1,tmpx+tmpxs+1);
    sort(tmpy+1,tmpy+tmpys+1);
    tmpxs = unique(tmpx+1,tmpx+tmpxs+1)-tmpx-1;
    tmpys = unique(tmpy+1,tmpy+tmpys+1)-tmpy-1;
    FOR(i,1,n){
        x[i]=lower_bound(tmpx+1,tmpx+tmpxs+1,x[i])-tmpx;
        y[i]=lower_bound(tmpy+1,tmpy+tmpys+1,y[i])-tmpy;
        
    }
    FOR(i,1,tmpxs) heng[i].clear();
    FOR(i,1,tmpys) shu[i].clear();

    FOR(i,1,n){
        heng[x[i]].push_back(tmpy[y[i]]);
        shu[y[i]].push_back(tmpx[x[i]]);
    }

    FOR(i,1,tmpxs)
        sort(heng[i].begin(),heng[i].end());
    FOR(i,1,tmpys)
        sort(shu[i].begin(),shu[i].end());
    Cheng.clear();
    Cshu.clear();
    Chengs=0;
    Cshus=0;
    FOR(i,1,tmpxs)
        for (int j=1;j<heng[i].size();++j)
            Cheng[make_pair(i,j)]=++Chengs;

    FOR(i,1,tmpys)
        for (int j=1;j<shu[i].size();++j)
            Cshu[make_pair(i,j)]=++Cshus;

    FOR(i,1,m) zuo[i]=you[i]=0;
    FOR(i,1,m){
        int x,y;
        scanf("%d%d",&x,&y);
        int t=lower_bound(tmpx+1,tmpx+tmpxs+1,x)-tmpx;
        if (t<=tmpxs && tmpx[t]==x){
            
            int id = lower_bound(heng[t].begin(),heng[t].end(),y)-heng[t].begin();
            if (id<heng[t].size() && id>0){
                // if (Cheng.find(make_pair(t,id))==Cheng.end()){
                //     Cheng[make_pair(t,id)]=++Chengs;
                // }
                zuo[i]=Cheng[make_pair(t,id)];
            }

        }
        t=lower_bound(tmpy+1,tmpy+tmpys+1,y)-tmpy;
        if (t<=tmpys && tmpy[t]==y){
            
            int id = lower_bound(shu[t].begin(),shu[t].end(),x)-shu[t].begin();
            if (id<shu[t].size() && id>0){
                // if (Cshu.find(make_pair(t,id))==Cshu.end()){
                //     Cshu[make_pair(t,id)]=++Cshus;
                // }
                you[i]=Cshu[make_pair(t,id)];
            }

        }
    }

    FOR(i,1,Chengs)
        Flow::Adde(0,i,1);
    FOR(i,1,Cshus)
        Flow::Adde(i+Chengs,Chengs+Cshus+1,1);
    FOR(i,1,Chengs) Solvablezuo[i]=0;
    FOR(i,1,Cshus) Solvableyou[i]=0;
    FOR(i,1,m){
        if (zuo[i]!=0 && you[i]!=0)
            fxb[i]=Flow::Adde(zuo[i],you[i]+Chengs,1);
        else
            fxb[i]=-1;
        if (zuo[i]!=0)
            Solvablezuo[zuo[i]]=1;
        if (you[i]!=0)
            Solvableyou[you[i]]=1;
    }
    int mxflow = Flow::Solve(0,Chengs+Cshus+1);
    Solvables=0;
    FOR(i,1,Chengs) Solvables+=Solvablezuo[i];
    FOR(i,1,Cshus) Solvables+=Solvableyou[i];
    

    printf("%d\n",Chengs+Cshus-min(mxflow+m-k,Solvables));
    int tot_used=0;

    FOR(i,1,Chengs) solvedzuo[i]=0;
    FOR(i,1,Cshus) solvedyou[i]=0;
    FOR(i,1,m) used[i]=0;
    FOR(i,1,m){
        if (fxb[i]!=-1){
            if (Flow::c[fxb[i]]==1){
                used[i]=1;
                tot_used++;
                solvedzuo[zuo[i]]=1;
                solvedyou[you[i]]=1;
            }
            else used[i]=0;
        }
    }
    FOR(i,1,m){
        if (tot_used >= m-k) break;
        if (used[i]!=1){
            if (zuo[i]!=0 && !solvedzuo[zuo[i]]){
                used[i]=1;
                solvedzuo[zuo[i]]=1;
                solvedyou[you[i]]=1;
                tot_used++;
            }
            else if (you[i]!=0 && !solvedyou[you[i]]){
                used[i]=1;
                solvedzuo[zuo[i]]=1;
                solvedyou[you[i]]=1;
                tot_used++;
            }
            
        }
    }

    if (tot_used<m-k){
        FOR(i,1,m) if (!used[i]){
            used[i]=1;
            ++tot_used;
            if (tot_used==m-k) break;
        }
    }

    FOR(i,1,m) if (!used[i]) printf("%d ",i);
    puts("");

    Flow::tot=1;
    FOR(i,0,Chengs+Cshus+1) Flow::fi[i]=0;
}
int main(){

    int T;
    scanf("%d",&T);
    while (T--) doit();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 36544kb

input:

3
8 6 4
1 3
2 1
2 6
4 1
4 7
6 1
6 3
6 6
2 3
3 1
4 3
4 6
5 2
6 4
3 2 1
10 12
10 10
10 11
1 4
1 5
1 3 2
1 1
2 1
2 2
2 3

output:

4
2 3 5 6 
2
2 
0
2 3 

result:

ok ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 215ms
memory: 40328kb

input:

1224
11 17 14
7 3
4 2
8 13
3 15
3 4
5 11
10 2
3 3
8 6
7 11
2 3
10 4
1 3
12 1
2 5
11 9
11 6
11 10
8 15
1 5
9 14
4 11
1 6
10 7
7 6
11 4
8 4
1 11
18 3 2
14 8
2 14
13 13
9 12
14 12
5 6
8 1
10 5
8 6
8 9
6 6
7 5
12 11
6 11
13 5
1 10
7 6
14 5
6 15
2 4
11 1
1 6 4
14 14
13 9
9 3
10 12
7 5
8 13
9 14
1 9 8
4 9...

output:

7
3 4 5 6 7 8 9 10 11 12 13 15 16 17 
15
2 3 
0
3 4 5 6 
0
2 3 4 5 6 7 8 9 
11
1 3 
8
1 2 3 
0
1 2 3 4 5 6 7 8 9 10 11 12 
1
5 6 7 9 10 11 12 
8
17 18 19 
1
1 2 3 4 5 6 7 8 
7
6 8 
10
13 14 15 
1
10 11 12 13 14 15 16 17 18 19 20 
0
1 
1
2 3 
0
5 6 7 
7
8 12 13 14 15 
2
10 11 12 13 14 
4
3 4 5 6 7 8 ...

result:

wrong answer Integer parameter [name=b_i] equals to 17, violates the range [1, 1] (test case 201)