QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#736728#5661. Multi-LaddersSanguineChameleon#RE 0ms0kbC++203.4kb2024-11-12 12:51:572024-11-12 12:51:57

Judging History

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

  • [2024-11-12 12:51:57]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-12 12:51:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i=a;i<(b);++i)
typedef pair<int,int> pii;

bool dfs(int a,int L, vector<vi>& g,vi& btoa, vi& A, vi& B){
    if(A[a] != L)return 0;
    A[a] = -1;
    for(int b:g[a]) if(B[b]==L+1){
        B[b]=0;
        if(btoa[b] == -1 || dfs(btoa[b], L+1, g, btoa, A, B)){
            return btoa[b]=a, 1;
        }
    }
    return 0;
}
int hK(vector<vi>& g, vi& btoa) {
    int res=0;
    vi A(g.size()), B(btoa.size()), cur, next;
    for(;;){
        fill(all(A), 0);
        fill(all(B), 0);
        for(int a:btoa) if (a!= -1) A[a]=-1;
            rep(a,0,g.size())if(A[a]==0)cur.pb(a);
        for(int lay=1;;lay++){
            bool isLast=0;
            next.clear();
            for(int a:cur){
                for(int b:g[a]){
                    if(btoa[b]==-1){
                        B[b]=lay;
                        isLast=1;
                    }else if(btoa[b]!=a && !B[b]){
                        B[b]=lay;
                        next.pb(btoa[b]);
                    }
                }
            }
            if(isLast)break;
            if(next.empty())return res;
            for(int a:next)A[a] = lay;
            cur.swap(next);
        }
        rep(a,0,g.size()){
            res+= dfs(a,0,g,btoa,A,B);
        }
    }
}


const int mxn=50005;

pair<pii,pii> gt[mxn],dd[mxn];
int area[mxn];
vi grid[2005][2005];

void solve(){
    int m,n;
    cin>>m>>n;
    for(int i=0;i<m;i++){//gt
        int x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        gt[i]={mp(x1,y1),mp(x2,y2)};
        area[i] = (x2-x1)*(y2-y1);
        for(int x=x1;x<=x2;x++){
            for(int y=y1;y<=y2;y++){
                grid[x][y].pb(i);
            }
        }
    }
    vector<vi> g;
    for(int i=0;i<n;i++){//detected
        int x1,y1,x2,y2;
        vi cur;
        cin>>x1>>y1>>x2>>y2;
        dd[i]={mp(x1,y1),mp(x2,y2)};
        vi merged;
        for(int x=x1;x<=x2;x++){
            for(int y=y1;y<=y2;y++){
                for(int ele:grid[x][y])merged.pb(ele);
            }
        }
        sort(merged.begin(),merged.end());
        merged.erase(unique(merged.begin(),merged.end()),merged.end());
        for(int id:merged){
            //d n g / g >= 1/2 --> d n g >= 2*g
            int nx1=max(x1,gt[id].f.f);
            int nx2=min(x2,gt[id].f.s);
            int ny1=max(y1,gt[id].s.f);
            int ny2=min(y2,gt[id].s.s);
            if((nx2-nx1)*(ny2-ny1) >= 2 * area[id]){
                //add edge
                cur.pb(id);
                cout<<i<<' '<<id<<'\n';
            }else{
                cout<<i<<' '<<id<<' '<<(nx2-nx1)*(ny2-ny1)<<' '<<area[id]<<'\n';
            }
        }
        g.pb(cur);
    }
    vi btoa(m,-1);
    cout<<hK(g,btoa)<<'\n';
    for(int i=0;i<=2000;i++){
        for(int j=0;j<=2000;j++)grid[i][j].clear();
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(0);
    int tc;
    cin>>tc;

    while(tc--){
        solve();
    }
}

/*
0 0 0 4
0 1 0 4
1 1 0 4
0
0 0 0 4
0 1 0 4
1 0 0 4
1 1 0 4
2 0 0 4
2 1 0 4
0
0 0 0 1
0 1 0 1
0 2 0 1
1 0 0 1
1 1 0 1
1 2 0 1
2 1 0 1
2 2 0 1
0

*/

详细

Test #1:

score: 0
Runtime Error

input:

1
2 3 3

output:


result: