QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#65138#5114. Cells Coloringbnu20DTWA 249ms12176kbC++203.8kb2022-11-27 18:04:202022-11-27 18:04:23

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-27 18:04:23]
  • 评测
  • 测评结果:WA
  • 用时:249ms
  • 内存:12176kb
  • [2022-11-27 18:04:20]
  • 提交

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, 0);
	rep(j, 1, m) maxf.add(j + n, maxf.t, 0);
	
	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::max(n, m)){
    	
    	// for(auto& i : maxf.e){
    		// if(i.from == maxf.s || i.to == maxf.t){
    			// i.cap = k;
    		// }
    	// }
    	
    	// int id = 0;
    	
    	for(int i = 0; i < n; i++) maxf.e[maxf.g[maxf.s][i]].cap++;
    	
    	for(int j = 0; j < m; j++) maxf.e[maxf.g[maxf.t][j] ^ 1].cap++;
    	
	    z += maxf.dinic();
	    
	    ans = std::min(ans, c * k + d * (sum - z));

		if(z == sum) break;
    }
    
    std::cout << ans << endl;
    
    return 0;
} 

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 9008kb

input:

3 4 2 1
.***
*..*
**..

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 3ms
memory: 9768kb

input:

3 4 1 2
.***
*..*
**..

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 83ms
memory: 10912kb

input:

250 250 965680874 9042302
..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.***
....**.*******.*.******...

output:

109972100048

result:

ok 1 number(s): "109972100048"

Test #4:

score: 0
Accepted
time: 114ms
memory: 9880kb

input:

250 250 62722280 506434
*.**.***.*.*....*....*...**.*..**..****.*.*..*.*.*..*.....**..*.*.*.*****.*.**..*.**....***..*..*.*.*.**.*..*..*.**..*...**....**..*.*.***.*****.*****.***..**.***.****....*.*.**.**.*...****....*..*.**.**********.......********...***.**..*.....**.*..*
.*..********..*...*..****...

output:

8437726048

result:

ok 1 number(s): "8437726048"

Test #5:

score: 0
Accepted
time: 245ms
memory: 11784kb

input:

250 250 85956327 344333
..*.............*...*.....*...*..........*.........*...*.......*..***......*.*........*.*........*........*..*..*.............*.*........*....*..*................***...................*..*.............*..*.....*..**..............*..*......*.....*..**
.........*......*.*.........

output:

18268031127

result:

ok 1 number(s): "18268031127"

Test #6:

score: -100
Wrong Answer
time: 249ms
memory: 12176kb

input:

250 250 768323813 489146
...*................*...........*.................*..***..*.......*..*......*.................*...*.........*.*.*.*...*.*.*.*.*.......*........*.............*...............*..*.............*.*...*.....................**.....**.....*.*........*......
...................*.......

output:

26645125505

result:

wrong answer 1st numbers differ - expected: '25999088192', found: '26645125505'