QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#549883 | #5668. Cell Nuclei Detection | Tiga_Pilot_2# | AC ✓ | 370ms | 91552kb | C++20 | 4.8kb | 2024-09-06 22:57:02 | 2024-09-06 22:57:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge {c b, e;};
sim > rge<c> range(c i, c j) {return rge<c>{i,j};}
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug{
~debug() {cerr << endl;}
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair <b, c> d) {
ris <<"(" <<d.fi <<", " <<d.se <<")";
}
sim dor(rge<c> d) {
*this << "[";
for(auto it=d.b;it!=d.e;++it) {
*this <<", " + 2*(it==d.b) <<*it;
}
ris << "]";
}
};
#define imie(...) "[" <<#__VA_ARGS__ ": " << (__VA_ARGS__) <<"]"
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = a; i > (b); --i)
#define ar array
#define sz(x) (int) (x).size()
#define pii pair<int,int>
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<double,int> pdi;
typedef vector<int> vi;
#define all(x) (x).begin(), (x).end()
template<typename T>
void min_self(T& A, T B) {
A = min(A,B);
}
template<typename T>
void max_self(T& A, T B) {
A = max(A,B);
}
const int mxn=5e4;
int m,n,t;
using pipi = tuple<int,int,int,int>;
pipi g[mxn],b[mxn];
struct Dinic {
struct Edge {
int to, rev;
ll c, oc;
ll flow() { return max(oc - c, 0LL); } // if you need flows
};
vi lvl, ptr, q;
vector<vector<Edge>> adj;
Dinic(int n) : lvl(n), ptr(n), q(n), adj(n) {}
void addEdge(int a, int b, ll c, ll rcap = 0) {
adj[a].push_back({b, sz(adj[b]), c, c});
adj[b].push_back({a, sz(adj[a]) - 1, rcap, rcap});
}
ll dfs(int v, int t, ll f) {
if (v == t || !f) return f;
for (int& i = ptr[v]; i < sz(adj[v]); i++) {
Edge& e = adj[v][i];
if (lvl[e.to] == lvl[v] + 1)
if (ll p = dfs(e.to, t, min(f, e.c))) {
e.c -= p, adj[e.to][e.rev].c += p;
return p;
}
}
return 0;
}
ll calc(int s, int t) {
ll flow = 0; q[0] = s;
rep(L,0,31) do { // 'int L=30' maybe faster for random data
lvl = ptr = vi(sz(q));
int qi = 0, qe = lvl[s] = 1;
while (qi < qe && !lvl[t]) {
int v = q[qi++];
for (Edge e : adj[v])
if (!lvl[e.to] && e.c >> (30 - L))
q[qe++] = e.to, lvl[e.to] = lvl[v] + 1;
}
while (ll p = dfs(s, t, LLONG_MAX)) flow += p;
} while (lvl[t]);
return flow;
}
bool leftOfMinCut(int a) { return lvl[a] != 0; }
};
void solve() {
cin >>m >>n;
int mxy = 0;
rep(i,0,m) {
int x1,y1,x2,y2; cin >>x1 >>y1 >>x2 >>y2;
if(x1>x2 || (x1==x2 && y1>y2)) {
swap(x1,x2);
swap(y1,y2);
}
g[i] = {x1,y1,x2,y2};
max_self(mxy, max(y1,y2));
}
rep(i,0,n) {
int x1,y1,x2,y2; cin >>x1 >>y1 >>x2 >>y2;
if(x1>x2 || (x1==x2 && y1>y2)) {
swap(x1,x2);
swap(y1,y2);
}
b[i] = {x1,y1,x2,y2};
max_self(mxy, max(y1,y2));
}
vector<set<pipi>> sg(mxy+1);
rep(i,0,m) {
auto [x1,y1,x2,y2] = g[i];
sg[y1].insert({x1,i,x2,y2});
}
Dinic dnc(n+m+2);
int st = n+m, tg=st+1;
rep(i,0,n) {
auto [x1,y1,x2,y2] = b[i];
// debug() <<imie(i) imie(x1) imie(y1) imie(x2) imie(y2);
rep(yi,max(0,y1-2),y2) {
auto it = sg[yi].lower_bound({x1-2,-1,-1,-1});
while(it!=sg[yi].end()) {
auto [p1,idg,p2,q2] = *it;
int q1 = yi;
if(p1>=x2) break;
int bx1 = max(x1,p1), by1= max(y1,q1), bx2 = min(x2,p2), by2 = min(y2,q2);
int ls = (p2-p1)*(q2-q1);
// debug() <<imie(idg) imie(p1) imie(q1) imie(p2) imie(q2);
// debug() <<imie(bx1) imie(bx2) imie(by1) imie(by2) imie(ls);
if(max(bx2-bx1,0)*max(by2-by1,0)*2>=ls) {
dnc.addEdge(i,idg+n,1);
}
it++;
}
}
}
rep(i,0,n) {
dnc.addEdge(st,i,1);
}
rep(i,0,m) {
dnc.addEdge(i+n,tg,1);
}
cout <<dnc.calc(st,tg) <<"\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >>t;
while(t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
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: 0ms
memory: 3608kb
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: 200ms
memory: 55264kb
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: 179ms
memory: 91552kb
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: 152ms
memory: 18224kb
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: 370ms
memory: 55364kb
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: 0ms
memory: 3568kb
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'