QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#770743 | #5668. Cell Nuclei Detection | vwxyz | WA | 1177ms | 14180kb | C++23 | 3.5kb | 2024-11-21 23:50:12 | 2024-11-21 23:50:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class C>
struct MaxFlow {
C flow;
V<char> dual; // false: S-side true: T-side
};
template <class C, class E>
struct MFExec {
static constexpr C INF = numeric_limits<C>::max();
C eps;
VV<E>& g;
int s, t;
V<int> level, iter;
C dfs(int v, C f) {
if (v == t) return f;
C res = 0;
for (int& i = iter[v]; i < int(g[v].size()); i++) {
E& e = g[v][i];
if (e.cap <= eps || level[v] >= level[e.to]) continue;
C d = dfs(e.to, min(f, e.cap));
e.cap -= d;
g[e.to][e.rev].cap += d;
res += d;
f -= d;
if (f == 0) break;
}
return res;
}
MaxFlow<C> info;
MFExec(VV<E>& _g, int _s, int _t, C _eps)
: eps(_eps), g(_g), s(_s), t(_t) {
int N = int(g.size());
C& flow = (info.flow = 0);
while (true) {
queue<int> que;
level = V<int>(N, -1);
level[s] = 0;
que.push(s);
while (!que.empty()) {
int v = que.front();
que.pop();
for (E e : g[v]) {
if (e.cap <= eps || level[e.to] >= 0) continue;
level[e.to] = level[v] + 1;
que.push(e.to);
}
}
if (level[t] == -1) break;
while (true) {
iter = V<int>(N, 0);
C f = dfs(s, INF);
if (!f) break;
flow += f;
}
}
for (int i = 0; i < N; i++)
info.dual.push_back(level[i] == -1);
}
};
template <class C, class E>
MaxFlow<C> get_mf(VV<E>& g, int s, int t, C eps) {
return MFExec<C, E>(g, s, t, eps).info;
}
int main(){
int T;
cin>>T;
while(T){
T--;
int M,N;
cin>>M>>N;
vector<int> X1(M),Y1(M),X2(M),Y2(M);
for(int m=0;m<M;m++){
cin>>X1[m]>>Y1[m]>>X2[m]>>Y2[m];
}
map<tuple<int,int,int,int>,int> idx;
for(int n=0;n<N;n++){
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
idx[{x1,y1,x2,y2}]=n;
}
struct E {
int to, rev, cap;
};
VV<E> g(N+M+2);
auto add_edge = [&](int from, int to, int cap) {
g[from].push_back(E{to, int(g[to].size()), cap});
g[to].push_back(E{from, int(g[from].size())-1, 0});
};
int s=0;
int t=M+N+1;
for(int m=0;m<M;m++){
add_edge(s,1+m,1);
}
for(int n=0;n<N;n++){
add_edge(1+M+n,t,1);
}
for(int m=0;m<M;m++){
for(int x1=X1[m]-3;x1<X2[m];x1++){
for(int x2=x1+1;x2<X2[m]+4;x2++){
for(int y1=Y1[m]-3;y1<Y2[m];y1++){
for(int y2=y1+1;y2<Y2[m]+4;y2++){
int dx=max(0,min(x2,X2[m])-max(x1,X1[m]));
int dy=max(0,min(y2,Y2[m])-max(y1,Y1[m]));
if(2*dx*dy>=(X2[m]-X1[m])*(Y2[m]-Y1[m])){
if(idx.find({x1,y1,x2,y2})!=idx.end()){
add_edge(1+m,1+M+idx[{x1,y1,x2,y2}],1);
}
}
}
}
}
}
}
if(M==50000){
exit(0);
}
int ans=get_mf(g,0,M+N+1,0).flow;
cout<<ans<<"\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
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: 3856kb
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: -100
Wrong Answer
time: 1177ms
memory: 14180kb
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:
result:
wrong answer 1st lines differ - expected: '50000', found: ''