QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#220096#5668. Cell Nuclei DetectionZIhan#AC ✓4897ms204644kbC++205.0kb2023-10-19 22:00:002023-10-19 22:00:01

Judging History

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

  • [2023-10-19 22:00:01]
  • 评测
  • 测评结果:AC
  • 用时:4897ms
  • 内存:204644kb
  • [2023-10-19 22:00:00]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define endl '\n'
#define IO ios::sync_with_stdio(0),cin.tie(0); 
using namespace std;
struct vec2{
    int x,y;
    bool operator==(const vec2& r){
        return x==r.x&&y==r.y;
    }
};
struct AABB{
    vec2 mn,mx;
    bool operator==(const AABB& r){
        return mn==r.mn&&mx==r.mx;
    }
    bool operator!=(const AABB& r){
        return !(*this == r);
    }
    int id;
};
bool intersect(const AABB& x, const AABB& y){
    return x.mx.x>=y.mn.x && y.mx.x>=x.mn.x&&
    x.mx.y>=y.mn.y && y.mx.y>=x.mn.y;
}
void printA(const AABB& x){
    cout<<"IN "<<x.mn.x<<' '<<x.mn.y<<", "
                <<x.mx.x<<' '<<x.mx.y<<'\n';
}
struct Dinic{
    struct Edge{
        int v,f,re;
    };
    #define SZ(x) (int)(x.size())
    vector<vector<Edge>> E;
    vector<int> level;
    int n,s,t;
    Dinic(int nn,int ss,int tt){
        n=nn;s=ss;t=tt;
        E.resize(n);
        level.resize(n);
    }
    void addEdge(int u,int v,int w){
        E[u].push_back({v,w,SZ(E[v])});
        E[v].push_back({u,0,SZ(E[u])-1});
    }
    bool bfs(){
        queue<int> q;
        q.push(s);
        level.assign(n,0);
        level[s]=1;
        while(q.size()){
            int u=q.front();q.pop();
            for(auto&it:E[u]){
                int v=it.v;
                if(it.f>0&&!level[v]){
                    level[v]=level[u]+1;
                    q.push(v);
                }
            }
        }
        return level[t];
    }
    int dfs(int u,int nf){
        if(u==t) return nf;
        int ret=0;
        for(auto&it:E[u]){
            int v=it.v;
            if(it.f>0&&level[v]==level[u]+1){
                int tem=dfs(v,min(it.f, nf));
                ret+=tem;nf-=tem;
                it.f-=tem;E[v][it.re].f+=tem;
                if(!nf)return ret;
            }
        }
        if(!ret)level[u]=0;
        return ret;
    }
    int flow(){
        int ret=0;
        while(bfs())ret+=dfs(s,0x3f3f3f3f);
        return ret;
    }
};
vector<pii>mp[2001][2001];
bool ch(AABB a,AABB b){
    //b要1/2
    int bb=(b.mx.x-b.mn.x)*(b.mx.y-b.mn.y);
    int x,y,xx,yy;
    xx=min(a.mx.x,b.mx.x);
    yy=min(a.mx.y,b.mx.y);
    x=max(a.mn.x,b.mn.x);
    y=max(a.mn.y,b.mn.y);
    //printA(a);
    //printA(b);
    //cout<<x<<" "<<y<<" "<<xx<<" "<<yy<<endl;
    int area=(xx-x)*(yy-y);
    if(2*area>=bb)return 1;
    else return 0;
}
signed main(){
    IO
    vector<AABB> a;
    int t;
    cin>>t;
    while(t--){
        a.clear();
        for(int i=0;i<=2000;i++){
            for(int j=0;j<=2000;j++){
                mp[i][j].clear();
            }
        }
        int n,m;
        cin>>n>>m;
        vector<AABB> dis;
        for(int i=0;i<n;i++){
            int x,y,xx,yy;
            cin>>x>>y>>xx>>yy;
            dis.push_back(AABB{{x,y},{xx,yy}});
        }
        sort(dis.begin(),dis.end(),[](AABB& a,AABB& b){
            if(a.mn.x!=b.mn.x) return a.mn.x<b.mn.x;
            if(a.mn.y!=b.mn.y) return a.mn.y<b.mn.y;
            if(a.mx.x!=b.mx.x) return a.mx.x<b.mx.x;
            return a.mx.y<b.mx.y;
        });
        dis[0].id = 0;
        a.push_back(dis[0]);
        int ids = 1;
        vector<int> num(n,1);
        for(int i=1;i<dis.size();i++){
            if(dis[i]!=dis[i-1]){
                dis[i].id=ids++;
                a.push_back(dis[i]);
            }
            else{
                num[ids-1]++;
            }
        }
        int nn=a.size();
        int s=0,t=nn+m+1;
        Dinic flow(1+nn+m+1,s,t);
        for(int i=0;i<a.size();i++){
            int x,xx,y,yy;
            x=a[i].mn.x;
            y=a[i].mn.y;
            xx=a[i].mx.x;
            yy=a[i].mx.y;
            for(int j=x;j<=xx;j++){
                for(int k=y;k<=yy;k++){
                    mp[j][k].push_back({i+1,num[i]});
                }
            }
            //cout<<s<<" "<<i+1<<endl;
            flow.addEdge(s,i+1,num[i]);
            //printA(a[i]);
            //cout<<num[i]<<endl;
        }
        for(int k=nn+1;k<=nn+m;k++){
            //cout<<k<<" "<<t<<endl;
            flow.addEdge(k,t,1);
        }
        for(int i=0;i<m;i++){
            set<pii>st;
            int x,y,xx,yy;
            cin>>x>>y>>xx>>yy;
            for(int j=x;j<=xx;j++){
                for(int k=y;k<=yy;k++){
                    for(auto ii:mp[j][k]){
                        st.insert(ii);
                    }
                }
            }
            AABB now;
            now.mn.x=x;
            now.mn.y=y;
            now.mx.x=xx;
            now.mx.y=yy;
            for(auto ii:st){
                AABB nxt;
                nxt=a[ii.first-1];
                if(ch(now,nxt)){
                    //cout<<ii.first<<" "<<nn+i+1<<endl;
                    flow.addEdge(ii.first,nn+1+i,1e9);
                }
            }
        }
        
        cout<<flow.flow()<<endl;
    }


}

详细

Test #1:

score: 100
Accepted
time: 30ms
memory: 97484kb

input:

3
2 2
1 1 3 3
3 3 5 5
2 2 4 4
4 4 6 6
2 3
1 1 3 3
3 3 5 5
1 3 3 5
2 1 4 5
3 1 5 3
3 3
1 1 2 2
2 2 3 3
3 3 4 4
1 1 3 3
2 2 4 4
3 3 5 5

output:

0
1
3

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 29ms
memory: 97612kb

input:

3
2 2
1 1 3 3
3 3 5 5
2 2 4 4
4 4 6 6
2 3
1 1 3 3
3 3 5 5
1 3 3 5
2 1 4 5
3 1 5 3
3 3
1 1 2 2
2 2 3 3
3 3 4 4
1 1 3 3
2 2 4 4
3 3 5 5

output:

0
1
3

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 2308ms
memory: 204644kb

input:

5
50000 50000
0 0 4 4
4 0 8 4
8 0 12 4
12 0 16 4
16 0 20 4
20 0 24 4
24 0 28 4
28 0 32 4
32 0 36 4
36 0 40 4
40 0 44 4
44 0 48 4
48 0 52 4
52 0 56 4
56 0 60 4
60 0 64 4
64 0 68 4
68 0 72 4
72 0 76 4
76 0 80 4
80 0 84 4
84 0 88 4
88 0 92 4
92 0 96 4
96 0 100 4
100 0 104 4
104 0 108 4
108 0 112 4
112 ...

output:

50000
50000
0
50000
3150

result:

ok 5 lines

Test #4:

score: 0
Accepted
time: 477ms
memory: 188364kb

input:

5
50000 50000
0 0 1 1
1 0 2 1
2 0 3 1
3 0 4 1
4 0 5 1
5 0 6 1
6 0 7 1
7 0 8 1
8 0 9 1
9 0 10 1
10 0 11 1
11 0 12 1
12 0 13 1
13 0 14 1
14 0 15 1
15 0 16 1
16 0 17 1
17 0 18 1
18 0 19 1
19 0 20 1
20 0 21 1
21 0 22 1
22 0 23 1
23 0 24 1
24 0 25 1
25 0 26 1
26 0 27 1
27 0 28 1
28 0 29 1
29 0 30 1
30 0 ...

output:

50000
25050
12500
16000
8000

result:

ok 5 lines

Test #5:

score: 0
Accepted
time: 348ms
memory: 140076kb

input:

5
50000 50000
0 0 2 4
4 0 7 1
8 0 10 1
12 0 15 3
16 0 19 1
20 0 22 2
24 0 26 4
28 0 30 4
32 0 36 3
36 0 40 1
40 0 44 1
44 0 47 2
48 0 49 3
52 0 54 1
56 0 59 4
60 0 64 3
64 0 68 3
68 0 70 1
72 0 76 4
76 0 80 3
80 0 84 4
84 0 87 2
88 0 90 1
92 0 94 4
96 0 98 1
100 0 104 1
104 0 107 2
108 0 110 4
112 0...

output:

10594
10779
10618
10381
10779

result:

ok 5 lines

Test #6:

score: 0
Accepted
time: 4897ms
memory: 175224kb

input:

5
50000 50000
0 0 4 4
1 0 5 4
2 0 6 4
3 0 7 4
4 0 8 4
5 0 9 4
6 0 10 4
7 0 11 4
8 0 12 4
9 0 13 4
10 0 14 4
11 0 15 4
12 0 16 4
13 0 17 4
14 0 18 4
15 0 19 4
16 0 20 4
17 0 21 4
18 0 22 4
19 0 23 4
20 0 24 4
21 0 25 4
22 0 26 4
23 0 27 4
24 0 28 4
25 0 29 4
26 0 30 4
27 0 31 4
28 0 32 4
29 0 33 4
30...

output:

50000
50000
50000
50000
49600

result:

ok 5 lines

Test #7:

score: 0
Accepted
time: 15ms
memory: 97420kb

input:

1
4 4
1 1 3 3
2 1 4 3
1 2 3 4
2 2 4 4
2 1 4 3
3 2 5 4
1 2 3 4
2 3 4 5

output:

3

result:

ok single line: '3'