QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#596745 | #9434. Italian Cuisine | ucup-team3646# | WA | 0ms | 3564kb | C++23 | 5.1kb | 2024-09-28 16:23:09 | 2024-09-28 16:23:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//using ll=long long;
struct Dinic{
struct Edge{
int to,rev;
ll cap;
};
static constexpr ll INF=2e18;
vector<vector<Edge>> G;
vector<int> level,iter;
Dinic()=default;
explicit Dinic(int V):G(V),level(V),iter(V){}
void add_edge(int u,int v,ll cap){
G[u].push_back({v,(int)G[v].size(),cap});
G[v].push_back({u,(int)G[u].size()-1,0});
}
ll max_flow(int s,int t){
ll flow=0;
while(bfs(s,t)){
fill(iter.begin(),iter.end(),0);
ll f=0;
while((f=dfs(s,t,INF))>0)flow+=f;
}
return flow;
}
set<int> min_cut(int s){
stack<int> st;
set<int> visited;
st.push(s);
visited.insert(s);
while(!st.empty()){
int v=st.top();
st.pop();
for(auto& e:G[v]){
if(e.cap>0&&!visited.count(e.to)){
visited.insert(e.to);
st.push(e.to);
}
}
}
return visited;
}
bool bfs(int s,int t){
fill(level.begin(),level.end(),-1);
level[s]=0;
queue<int> q;
q.push(s);
while(!q.empty()&&level[t]==-1){
int v=q.front();
q.pop();
for(auto &e: G[v]){
if(e.cap>0&&level[e.to]==-1){
level[e.to]=level[v]+1;
q.push(e.to);
}
}
}
return level[t]!=-1;
}
ll dfs(int v,int t,ll f){
if(v==t)return f;
for(int&i=iter[v];i<(int)G[v].size();++i){
Edge&e=G[v][i];
if(e.cap>0&&level[v]<level[e.to]){
ll d=dfs(e.to,t,min(f,e.cap));
if(d>0){
e.cap-=d;
G[e.to][e.rev].cap+=d;
return d;
}
}
}
return 0;
}
};
void solve() {
ll N, M, K; cin >> N >> M >> K;
vector< array<ll, 2> > castles(N), walls(M);
set<ll> zatx, zaty;
// casltle
for (int i = 0; i < N; ++i) {
ll x, y; cin >> x >> y;
castles[i] = {x, y};
zatx.insert(x), zaty.insert(y);
}
// wall
for (int i = 0; i < M; ++i) {
ll x, y; cin >> x >> y;
walls[i] = {x, y};
zatx.insert(x), zaty.insert(y);
}
map<ll, ll> mpx, mpy;
ll X, Y;
{ // zaatsu
ll num = 0;
for (auto x : zatx) {
mpx[x] = num++;
}
X = num;
num = 0;
for (auto y : zaty) {
mpy[y] = num++;
}
Y = num;
}
vector<vector< array<ll, 2> >> row(X), col(Y);
for (int i = 0; i < N; ++i) {
auto [x, y] = castles[i];
x = mpx[x], y = mpy[y];
row[x].push_back({y, i});
col[y].push_back({x, i});
castles[i] = {x, y};
// cout << x << " " << y << endl;
}
for (int i = 0; i < M; ++i) {
auto [x, y] = walls[i];
x = mpx[x], y = mpy[y];
walls[i] = {x, y};
}
for (int x = 0; x < X; ++x) {
sort(row[x].begin(), row[x].end());
}
for (int y = 0; y < Y; ++y) {
sort(col[y].begin(), col[y].end());
}
// corrision
map< array<ll, 2>, ll> cor;
set< array<ll, 2> > rest_pair;
ll RP, CP;
{
// row
ll num = 0;
for (int x = 0; x < X; ++x) {
for (int i = 0; i+1 < row[x].size(); ++i) {
auto [y0, i0] = row[x][i];
auto [y1, i1] = row[x][i+1];
cor[{i0, i1}] = num++;
rest_pair.insert({i0, i1});
// cout << i0 << " " << i1 << endl;
}
}
RP = num;
for (int y = 0; y < Y; ++y) {
for (int i = 0; i+1 < col[y].size(); ++i) {
auto [x0, i0] = col[y][i];
auto [x1, i1] = col[y][i+1];
cor[{i0, i1}] = num++;
rest_pair.insert({i0, i1});
// cout << i0 << " " << i1 << endl;
}
}
CP = num - RP;
}
// wal[i] = {row, col}
vector< array<ll, 2> > wal(M, {-1, -1});
for (int i = 0; i < M; ++i) {
auto [x, y] = walls[i];
// cout << i << " " << x << " " << y << endl;
{
// row
array<ll, 2> ar = {y, 0};
auto itr = upper_bound(row[x].begin(), row[x].end(), ar);
if (itr != row[x].end() && itr != row[x].begin()) {
auto [y1, i1] = *itr;
itr--;
auto [y0, i0] = *itr;
wal[i][0] = cor[{i0, i1}];
}
// col
ar = {x, 0};
itr = upper_bound(col[y].begin(), col[y].end(), ar);
if (itr != col[y].end() && itr != col[y].begin()) {
auto [x1, i1] = *itr;
itr--;
auto [x0, i0] = *itr;
wal[i][1] = cor[{i0, i1}];
}
}
// cout << i << " " << wal[i][0] << " " << wal[i][1] << endl;
}
// make flow graph
ll S = RP + CP, T = S + 1;
Dinic mf(T + 1);
for (int r = 0; r < RP; ++r) {
mf.add_edge(S, r, 1);
}
for (int c = 0; c < CP; ++c) {
mf.add_edge(RP + c, T, 1);
}
return;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
ll T; cin >> T;
while (T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3564kb
input:
3 5 1 1 1 0 0 1 0 5 0 3 3 0 5 6 2 4 1 2 0 4 0 6 3 4 6 2 6 0 3 4 3 3 1 3 0 6 3 3 6 0 3
output:
result:
wrong answer Answer contains longer sequence [length = 3], but output contains 0 elements