QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#528053 | #6113. Window Arrangement | fishy15 | Compile Error | / | / | C++20 | 4.8kb | 2024-08-23 05:49:06 | 2024-08-23 05:49:07 |
Judging History
answer
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <numeric>
#define ll long long
#define ld long double
#define eps 1e-8
#define MOD 1000000007
#define INFLL 0x3f3f3f3f3f3f3f3f
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#include <bits/extc++.h>
using namespace std;
using vi = vector<int>;
const ll INF = numeric_limits<ll>::max() / 4;
struct MCMF {
struct edge {
int from, to, rev;
ll cap, cost, flow;
};
int N;
vector<vector<edge>> ed;
vi seen;
vector<ll> dist, pi;
vector<edge*> par;
MCMF(int N) : N(N), ed(N), seen(N), dist(N), pi(N), par(N) {}
void addEdge(int from, int to, ll cap, ll cost) {
if (from == to) return;
ed[from].push_back(edge {from,to,sz(ed[to]),cap,cost,0 });
ed[to].push_back(edge {to,from,sz(ed[from])-1,0,-cost,0 });
}
void path(int s) {
fill(all(seen), 0);
fill(all(dist), INF);
dist[s] = 0; ll di;
__gnu_pbds::priority_queue<pair<ll, int>> q;
vector<decltype(q)::point_iterator> its(N);
q.push({ 0, s });
while (!q.empty()) {
s = q.top().second; q.pop();
seen[s] = 1; di = dist[s] + pi[s];
for (edge& e : ed[s]) if (!seen[e.to]) {
ll val = di - pi[e.to] + e.cost;
if (e.cap - e.flow > 0 && val < dist[e.to]) {
dist[e.to] = val;
par[e.to] = &e;
if (its[e.to] == q.end())
its[e.to] = q.push({ -dist[e.to], e.to });
else
q.modify(its[e.to], { -dist[e.to], e.to });
}
}
}
rep(i,0,N) pi[i] = min(pi[i] + dist[i], INF);
}
pair<ll, ll> maxflow(int s, int t) {
ll totflow = 0, totcost = 0;
while (path(s), seen[t]) {
ll fl = INF;
for (edge* x = par[t]; x; x = par[x->from])
fl = min(fl, x->cap - x->flow);
totflow += fl;
for (edge* x = par[t]; x; x = par[x->from]) {
x->flow += fl;
ed[x->to][x->rev].flow -= fl;
}
}
rep(i,0,N) for(edge& e : ed[i]) totcost += e.cost * e.flow;
return {totflow, totcost/2};
}
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector p(n, vector<int>(m));
vector w(n, vector<int>(m));
rep(i, 0, n) {
rep(j, 0, m) {
cin >> p[i][j];
}
}
rep(i, 0, n) {
rep(j, 0, m) {
cin >> w[i][j];
}
}
auto room = [&](int x, int y) {
return x * m + y;
};
// n x (m + 1) of these
auto vert_wall = [&](int x, int y) {
return n * m + x * (m + 1) + y;
};
// (n + 1) x m of these
auto horz_wall = [&](int x, int y) {
return n * m + n * (m + 1) + x * m + y;
};
auto left = [&](int x, int y) { return horz_wall(x, y); };
auto right = [&](int x, int y) { return horz_wall(x, y+1); };
auto up = [&](int x, int y) { return vert_wall(x, y); };
auto down = [&](int x, int y) { return vert_wall(x+1, y); };
int src = (n * m) + (n * (m + 1)) + ((n + 1) * m);
int sink = src + 1;
MCMF mcmf(sink + 1);
rep(i, 0, n) {
rep(j, 0, m) {
mcmf.addEdge(src, room(i, j), w[i][j], 0);
mcmf.addEdge(room(i, j), left(i, j), 1, 0);
mcmf.addEdge(room(i, j), right(i, j), 1, 0);
mcmf.addEdge(room(i, j), up(i, j), 1, 0);
mcmf.addEdge(room(i, j), down(i, j), 1, 0);
}
}
rep(i, 0, n) {
rep(j, 0, m+1) {
int betw_cost;
if (j > 0 && j < m) {
betw_cost = p[i][j - 1] * p[i][j];
} else {
betw_cost = 0;
}
mcmf.addEdge(vert_wall(i, j), sink, 1, 0);
mcmf.addEdge(vert_wall(i, j), sink, 1, betw_cost);
}
}
rep(i, 0, n+1) {
rep(j, 0, m) {
int betw_cost;
if (i > 0 && i < n) {
betw_cost = p[i - 1][j] * p[i][j];
} else {
betw_cost = 0;
}
mcmf.addEdge(horz_wall(i, j), sink, 1, 0);
mcmf.addEdge(horz_wall(i, j), sink, 1, betw_cost);
}
}
cout << mcmf.maxflow(src, sink).second << '\n';
return 0;
}
Details
/usr/include/c++/13/ranges: In constructor ‘constexpr std::ranges::lazy_split_view<_Vp, _Pattern>::lazy_split_view(_Range&&, std::ranges::range_value_t<_Range>)’: answer.code:25:16: error: ‘begin’ is not a member of ‘std::ranges::views’ 25 | #define all(x) begin(x), end(x) | ^~~~~ answer.code:25:16: note: suggested alternatives: In file included from /usr/include/c++/13/string:53, from /usr/include/c++/13/bits/locale_classes.h:40, from /usr/include/c++/13/bits/ios_base.h:41, from /usr/include/c++/13/ios:44, from /usr/include/c++/13/ostream:40, from /usr/include/c++/13/iostream:41, from answer.code:1: /usr/include/c++/13/bits/range_access.h:114:37: note: ‘std::begin’ 114 | template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept; | ^~~~~ In file included from /usr/include/c++/13/string_view:48, from /usr/include/c++/13/bits/basic_string.h:47, from /usr/include/c++/13/string:54: /usr/include/c++/13/bits/ranges_base.h:489:44: note: ‘std::ranges::__cust::begin’ 489 | inline constexpr __cust_access::_Begin begin{}; | ^~~~~ In file included from /usr/include/c++/13/bits/stl_iterator_base_types.h:71, from /usr/include/c++/13/bits/stl_construct.h:61, from /usr/include/c++/13/bits/char_traits.h:57, from /usr/include/c++/13/ios:42: /usr/include/c++/13/bits/iterator_concepts.h:969:10: note: ‘std::ranges::__cust_access::begin’ 969 | void begin(const auto&) = delete; | ^~~~~ /usr/include/c++/13/ranges: In constructor ‘constexpr std::ranges::split_view<_Vp, _Pattern>::split_view(_Range&&, std::ranges::range_value_t<_Range>)’: answer.code:25:16: error: ‘begin’ is not a member of ‘std::ranges::views’ 25 | #define all(x) begin(x), end(x) | ^~~~~ answer.code:25:16: note: suggested alternatives: /usr/include/c++/13/bits/range_access.h:114:37: note: ‘std::begin’ 114 | template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept; | ^~~~~ /usr/include/c++/13/bits/ranges_base.h:489:44: note: ‘std::ranges::__cust::begin’ 489 | inline constexpr __cust_access::_Begin begin{}; | ^~~~~ /usr/include/c++/13/bits/iterator_concepts.h:969:10: note: ‘std::ranges::__cust_access::begin’ 969 | void begin(const auto&) = delete; | ^~~~~ /usr/include/c++/13/ranges: At global scope: answer.code:25:16: error: ‘begin’ is not a member of ‘std::ranges::views’ 25 | #define all(x) begin(x), end(x) | ^~~~~ answer.code:25:16: note: suggested alternatives: /usr/include/c++/13/bits/range_access.h:114:37: note: ‘std::begin’ 114 | template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept; | ^~~~~ /usr/include/c++/13/bits/ranges_base.h:489:44: note: ‘std::ranges::__cust::begin’ 489 | inline constexpr __cust_access::_Begin begin{}; | ^~~~~ /usr/include/c++/13/bits/iterator_concepts.h:969:10: note: ‘std::ranges::__cust_access::begin’ 969 | void begin(const auto&) = delete; | ^~~~~ /usr/include/c++/13/ranges: In member function ‘constexpr auto std::ranges::views::_Common::operator()(_Range&&) const’: answer.code:25:16: error: ‘begin’ is not a member of ‘std::ranges::views’ 25 | #define all(x) begin(x), end(x) | ^~~~~ answer.code:25:16: note: suggested alternatives: /usr/include/c++/13/bits/range_access.h:114:37: note: ‘std::begin’ 114 | template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept; | ^~~~~ /usr/include/c++/13/bits/ranges_base.h:489:44: note: ‘std::ranges::__cust::begin’ 489 | inline constexpr __cust_access::_Begin begin{}; | ^~~~~ /usr/include/c++/13/bits/iterator_concepts.h:969:10: note: ‘std::ranges::__cust_access::begin’ 969 | void begin(const auto&) = delete; | ^~~~~