QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#668213 | #5114. Cells Coloring | SCUTkk | WA | 404ms | 7876kb | C++20 | 3.1kb | 2024-10-23 12:35:42 | 2024-10-23 12:35:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i64 = long long;
using pii = pair<int, int>;
using db = double;
#define cY cout << "YES\n"
#define cN cout << "NO\n"
#define cA cout << ans << "\n"
#define pb push_back
const int N = 2e5 + 7;
const ll mod = 998244353;
const ll MOD = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
template <class T>
struct Flow {
const int n;
std::vector<std::pair<int, T>> e;
std::vector<std::vector<int>> g;
std::vector<int> cur, dep;
Flow(int n) : n(n), g(n) {}
bool bfs(int s, int t) {
dep.assign(n, -1);
std::queue<int> q;
dep[s] = 0;
q.push(s);
while (!q.empty()) {
const int u = q.front();
q.pop();
for (int i : g[u]) {
auto [v, c] = e[i];
if (c > 0 and dep[v] == -1) {
dep[v] = dep[u] + 1;
if (v == t)
return true;
q.push(v);
}
}
}
return false;
}
T dfs(int u, int t, T f) {
if (u == t) {
return f;
}
T res = f;
for (int &i = cur[u]; i < g[u].size(); i++) {
const int j = g[u][i];
auto [v, c] = e[j];
if (c > 0 and dep[v] == dep[u] + 1) {
T out = dfs(v, t, std::min(res, c));
e[j].second -= out;
e[j ^ 1].second += out;
res -= out;
if (res == 0) {
return f;
}
}
}
return f - res;
}
void add(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 work(int s, int t) {
T ans = 0;
while (bfs(s, t)) {
cur.assign(n, 0);
ans += dfs(s, t, std::numeric_limits<T>::max());
}
return ans;
}
};
#define int ll
void crossparallel() {
int n, m, c, d;
cin >> n >> m >> c >> d;
vector<string> mp(n);
for (int i = 0; i < n; i++) cin >> mp[i];
int ans = INF;
for (int k = 1; k <= max(n, m); k++) {
Flow<int> flow(n + m + 3);
int s = n + m + 1, t = n + m + 2;
int cnt = 0;
for (int i = 0; i < n; i++)
flow.add(s, i, k);
for (int i = 0; i < m; i++)
flow.add(i + n, t, k);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (mp[i][j] == '.') {
cnt++;
flow.add(i, j + n, 1);
}
}
}
auto z = cnt - flow.work(s, t);
ans = min(ans, c * k + d * z);
}
cA;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
crossparallel();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3772kb
input:
3 4 2 1 .*** *..* **..
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
3 4 1 2 .*** *..* **..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 276ms
memory: 5184kb
input:
250 250 965680874 9042302 ..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.*** ....**.*******.*.******...
output:
109972100048
result:
ok 1 number(s): "109972100048"
Test #4:
score: 0
Accepted
time: 316ms
memory: 5532kb
input:
250 250 62722280 506434 *.**.***.*.*....*....*...**.*..**..****.*.*..*.*.*..*.....**..*.*.*.*****.*.**..*.**....***..*..*.*.*.**.*..*..*.**..*...**....**..*.*.***.*****.*****.***..**.***.****....*.*.**.**.*...****....*..*.**.**********.......********...***.**..*.....**.*..* .*..********..*...*..****...
output:
8437726048
result:
ok 1 number(s): "8437726048"
Test #5:
score: 0
Accepted
time: 404ms
memory: 7876kb
input:
250 250 85956327 344333 ..*.............*...*.....*...*..........*.........*...*.......*..***......*.*........*.*........*........*..*..*.............*.*........*....*..*................***...................*..*.............*..*.....*..**..............*..*......*.....*..** .........*......*.*.........
output:
18268031127
result:
ok 1 number(s): "18268031127"
Test #6:
score: -100
Wrong Answer
time: 388ms
memory: 7348kb
input:
250 250 768323813 489146 ...*................*...........*.................*..***..*.......*..*......*.................*...*.........*.*.*.*...*.*.*.*.*.......*........*.............*...............*..*.............*.*...*.....................**.....**.....*.*........*...... ...................*.......
output:
26645125505
result:
wrong answer 1st numbers differ - expected: '25999088192', found: '26645125505'