QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578408 | #9345. Artful Paintings | Yukari# | WA | 13ms | 24904kb | C++20 | 3.4kb | 2024-09-20 18:55:43 | 2024-09-20 18:55:44 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using i64 = long long;
const int inf = 1e9;
template <class T>
struct MaxFlow {
struct _edge {
int to;
T cap;
_edge(int to, T cap) : to(to), cap(cap) {}
};
int n;
vector<_edge> e;
vector<vector<int>> g;
vector<int> cur, h;
MaxFlow() {}
MaxFlow(int n) { init(n); }
void init(int n) {
this->n = n;
e.clear();
g.assign(n, {});
cur.resize(n);
h.resize(n);
}
bool bfs(int s, int t) {
h.assign(n, -1);
queue<int> que;
h[s] = 0;
que.push(s);
while (!que.empty()) {
const int u = que.front();
que.pop();
for (int i : g[u]) {
auto [v, c] = e[i];
if (c > 0 && h[v] == -1) {
h[v] = h[u] + 1;
if (v == t) return true;
que.push(v);
}
}
}
return false;
}
T dfs(int u, int t, T f) {
if (u == t) return f;
auto r = f;
for (int &i = cur[u]; i < int(g[u].size()); i++) {
const int j = g[u][i];
auto [v, c] = e[j];
if (c > 0 && h[v] == h[u] + 1) {
auto a = dfs(v, t, min(r, c));
e[j].cap -= a;
e[j ^ 1].cap += a;
r -= a;
if (r == 0) return f;
}
}
return f - r;
}
void addEdge(int u, int v, T c) {
g[u].push_back(e.size());
e.emplace_back(v, c);
g[v].push_back(e.size());
e.emplace_back(u, 0);
}
T flow(int s, int t) {
T ans = 0;
while (bfs(s, t)) {
cur.assign(n, 0);
ans += dfs(s, t, numeric_limits<T>::max());
}
return ans;
}
struct Edge {
int from, to;
T cap, flow;
};
vector<Edge> edges() {
vector<Edge> a;
for (int i = 0; i < e.size(); i += 2) {
Edge x;
x.from = e[i + 1].to;
x.to = e[i].to;
x.cap = e[i].cap + e[i + 1].cap;
x.flow = e[i + 1].cap;
a.push_back(x);
}
return a;
}
};
void solve() {
int n, m1, m2;
cin >> n >> m1 >> m2;
int S = 0, T = m1 + m2 + n + 1;
MaxFlow<i64> mf(T + 1);
for (int i = 1, l1, l2, k; i <= m1; i++) {
// cout << "yes\n";
cin >> l1 >> l2 >> k;
mf.addEdge(S, i, k);
for (int j = l1; j <= l2; j++)
mf.addEdge(i, m1 + m2 + j, 1);
}
for (int i = 1, l1, l2, k; i <= m2; i++) {
// cout << "yes\n";
cin >> l1 >> l2 >> k;
mf.addEdge(S, m1 + i, k);
for (int j = 1; j < l1; j++)
mf.addEdge(m1 + i, m1 + m2 + j, 1);
for (int j = l2 + 1; j <= n; j++)
mf.addEdge(m1 + i, m1 + m2 + j, 1);
}
// cout << "yes\n";
for (int i = 1; i <= n; i++)
mf.addEdge(m1 + m2 + i, T, inf);
// cout << "yes\n";
auto ans = mf.flow(S, T);
i64 res = 0;
for (auto &v : mf.g[T]) {
if (mf.e[v].cap) res += 1;
}
cout << res << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
1 3 1 1 1 2 1 2 2 1
output:
1
result:
ok single line: '1'
Test #2:
score: -100
Wrong Answer
time: 13ms
memory: 24904kb
input:
1 1000 500 500 479 860 170 73 939 25 363 772 30 185 584 89 326 482 10 784 949 23 384 740 114 233 693 45 167 724 211 217 436 95 46 701 153 138 585 67 321 388 11 114 890 194 407 854 74 438 845 117 9 718 259 393 576 35 182 707 257 451 766 136 150 382 31 468 785 40 202 490 46 326 815 59 272 441 77 123 8...
output:
946
result:
wrong answer 1st lines differ - expected: '492', found: '946'