QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65131 | #5114. Cells Coloring | bnu20DT | WA | 280ms | 13844kb | C++17 | 3.6kb | 2022-11-27 17:45:47 | 2022-11-27 17:45:50 |
Judging History
answer
// created on Lucian Xu's Laptop
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <utility>
#include <unordered_map>
#include <ctime>
#include <random>
// using namespace std;
typedef unsigned int UI;
typedef unsigned long long ULL;
typedef long long LL;
typedef unsigned long long ULL;
typedef std::pair<int, int> PII;
typedef std::pair<int, LL> PIL;
typedef std::pair<LL, int> PLI;
#define rep(i, l, r) for(auto i = (l); i <= (r); i++)
#define per(i, r, l) for(auto i = (r); i >= (l); i--)
#define ff first
#define ss second
#define makepair make_pair
#define pushback push_back
#define endl '\n'
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
const int N = 2e5+10;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const LL INF = 1e18;
const double pi = acos(-1.0);
const double eps = 1e-6;
ULL add(ULL a, ULL b) {return a + b < mod ? a + b : a + b - mod;}
ULL minus(ULL a, ULL b) {return a < b ? a + mod - b : a - b;}
ULL mul(ULL a, ULL b) {return a * b % mod;}
struct edge{
int from, to;
LL cap, flow;
edge(int u, int v, LL c, LL f) : from(u), to(v), cap(c), flow(f) {}
};
struct Dinic{
int n, m = 0, s, t;
std::vector<edge> e;
std::vector<int> g[N];
int d[N], cur[N];
bool vis[N];
void init(int n){
m = 0;
for(int i = 0; i <= n; i++){
g[i].clear();
d[i] = cur[i] = 0;
vis[i] = false;
}
e.clear();
}
void add(int from, int to, LL cap){
e.push_back(edge(from, to, cap, 0));
e.push_back(edge(to, from, 0, 0));
g[from].push_back(m++);
g[to].push_back(m++);
}
bool bfs(){
rep(i, 1, n) vis[i] = false;
std::queue<int> q;
q.push(s), d[s] = 0, vis[s] = 1;
while(!q.empty()){
int u = q.front(); q.pop();
for(int i = 0; i < g[u].size(); i++){
edge& ee = e[g[u][i]];
if(!vis[ee.to] && ee.cap > ee.flow){
vis[ee.to] = 1;
d[ee.to] = d[u] + 1;
q.push(ee.to);
}
}
}
return vis[t];
}
LL dfs(int u, LL now){
if (u == t || now == 0) return now;
LL flow = 0, f;
for(int& i = cur[u]; i < g[u].size(); i++){
edge& ee = e[g[u][i]], & er = e[g[u][i] ^ 1];
if (d[u] + 1 == d[ee.to] && (f = dfs(ee.to, std::min(now, ee.cap - ee.flow))) > 0) {
ee.flow += f, er.flow -= f;
flow += f, now -= f;
if(now == 0) break;
}
}
return flow;
}
LL dinic(){
LL ans = 0;
while(bfs()){
rep(i, 1, n) cur[i] = 0;
ans += dfs(s, INF);
}
return ans;
}
};
Dinic maxf;
int n, m, sum;
LL c, d, z, ans = INF;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::cin >> n >> m >> c >> d;
maxf.n = n * m + 2, maxf.s = n * m + 1, maxf.t = n * m + 2;
rep(i, 1, n) maxf.add(maxf.s, i, 1);
rep(j, 1, m) maxf.add(j + n, maxf.t, 1);
rep(i, 1, n){
rep(j, 1, m){
char ch; std::cin >> ch;
if(ch == '.') maxf.add(i, j + n, 1), sum++;
}
}
rep(k, 1, std::min(n, m)){
for(auto& i : maxf.e){
if(i.from == maxf.s || i.from == maxf.t || i.to == maxf.s || i.to == maxf.t){
if(i.cap > 0) i.cap = k;
}
}
z += maxf.dinic();
ans = std::min(ans, c * k + d * (sum - z));
}
std::cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 9520kb
input:
3 4 2 1 .*** *..* **..
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 8304kb
input:
3 4 1 2 .*** *..* **..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 107ms
memory: 10216kb
input:
250 250 965680874 9042302 ..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.*** ....**.*******.*.******...
output:
109972100048
result:
ok 1 number(s): "109972100048"
Test #4:
score: 0
Accepted
time: 137ms
memory: 10920kb
input:
250 250 62722280 506434 *.**.***.*.*....*....*...**.*..**..****.*.*..*.*.*..*.....**..*.*.*.*****.*.**..*.**....***..*..*.*.*.**.*..*..*.**..*...**....**..*.*.***.*****.*****.***..**.***.****....*.*.**.**.*...****....*..*.**.**********.......********...***.**..*.....**.*..* .*..********..*...*..****...
output:
8437726048
result:
ok 1 number(s): "8437726048"
Test #5:
score: 0
Accepted
time: 279ms
memory: 11476kb
input:
250 250 85956327 344333 ..*.............*...*.....*...*..........*.........*...*.......*..***......*.*........*.*........*........*..*..*.............*.*........*....*..*................***...................*..*.............*..*.....*..**..............*..*......*.....*..** .........*......*.*.........
output:
18268031127
result:
ok 1 number(s): "18268031127"
Test #6:
score: -100
Wrong Answer
time: 280ms
memory: 13844kb
input:
250 250 768323813 489146 ...*................*...........*.................*..***..*.......*..*......*.................*...*.........*.*.*.*...*.*.*.*.*.......*........*.............*...............*..*.............*.*...*.....................**.....**.....*.*........*...... ...................*.......
output:
26645125505
result:
wrong answer 1st numbers differ - expected: '25999088192', found: '26645125505'