QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#438147#5202. DominoeszhaohaikunWA 1231ms6032kbC++203.4kb2024-06-10 11:24:372024-06-10 11:24:38

Judging History

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

  • [2024-06-10 11:24:38]
  • 评测
  • 测评结果:WA
  • 用时:1231ms
  • 内存:6032kb
  • [2024-06-10 11:24:37]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "\033[32m[" << __LINE__ << "]\033[0m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T& x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T& x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = - f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
const int N = 2010, inf = 1e9;
int n, m, cnt, id[N][N];
string st[N];
// namespace MAXFLOW {
struct edge {
	int dest, flow;
	unsigned pos;
};
vector <edge> v[N];
int s, t;
void addedge(int x, int y, int flow, int flow2 = 0) {
	v[x].emplace_back((edge) {y, flow, (unsigned) v[y].size()});
	v[y].emplace_back((edge) {x, flow2, (unsigned) v[x].size() - 1});
}
queue <int> q;
int dep[N];
unsigned cur[N];
bool bfs() {
	F(i, s, t) dep[i] = 0;
	dep[s] = 1;
	q.push(s);
	while (q.size()) {
		int x = q.front(); q.pop();
		for (edge i: v[x])
			if (i.flow && !dep[i.dest]) {
				dep[i.dest] = dep[x] + 1;
				q.push(i.dest);
			}
	}
	return dep[t];
}
int dfs(int x, int flow) {
	if (x == t) return flow;
	int ans = 0, t;
	for (unsigned& i = cur[x]; i < v[x].size(); ++i)
		if (v[x][i].flow && dep[v[x][i].dest] == dep[x] + 1 && (t = dfs(v[x][i].dest, min(flow, v[x][i].flow)))) {
			flow -= t, ans += t;
			v[x][i].flow -= t, v[v[x][i].dest][v[x][i].pos].flow += t;
			if (!flow) break;
		}
	return ans;
}
ll dinic() {
	ll ans = 0;
	while (bfs()) {
		F(i, s, t) cur[i] = 0;
		ans += dfs(s, inf);
	}
	return ans;
}
// }
// using MAXFLOW::s;
// using MAXFLOW::t;
// using MAXFLOW::dinic;
// using MAXFLOW::addedge;
bool vv[N];
int ans;
void dfs2(int x) {
	if (vv[x]) return;
	vv[x] = true;
	ans++;
	for (edge i: v[x])
		if (!i.flow) {
			int w = i.dest, pos = - 1;
			for (edge j: v[w])
				if (!j.flow) {
					assert(!~pos);
					pos = j.dest;
				}
			dfs2(pos);
		}
}
signed main() {
	cin >> n >> m;
	F(i, 1, n) {
		cin >> st[i];
		st[i] = ' ' + st[i];
		F(j, 1, m) {
			if (st[i][j] == '.') {
				if (++cnt > 2000) {
					cout << 1e6;
					return 0;
				}
			}
		}
	}
	t = cnt;
	F(ti, 1, n)
		F(tj, 1, m)
			if (st[ti][tj] == '.' && (ti + tj) % 2 == 0) {
				st[ti][tj] = '#';
				F(i, s, t) v[i].clear();
				cnt = 0;
				F(i, 1, n) {
					F(j, 1, m) {
						if (st[i][j] == '.') {
							id[i][j] = ++cnt;
							if ((i + j) & 1) addedge(id[i][j], t, 1);
							else addedge(s, id[i][j], 1);
							if (i > 1 && st[i - 1][j] == '.') {
								if ((i + j) & 1) addedge(id[i - 1][j], id[i][j], 1);
								else addedge(id[i][j], id[i - 1][j], 1);
							}
							if (j > 1 && st[i][j - 1] == '.') {
								if ((i + j) & 1) addedge(id[i][j - 1], id[i][j], 1);
								else addedge(id[i][j], id[i][j - 1], 1);
							}
						}
					}
				}
				dinic();
				int pos = - 1;
				for (edge i: v[t])
					if (!i.flow) {
						assert(!~pos);
						pos = i.dest;
					}
				ms(vv, false);
				dfs2(pos);
				st[ti][tj] = '.';
				// debug << ti << " " << tj << " " << ans << endl;
			}
	cout << (ll) t * (t - 1) / 2 - ans;
	return 0;
}
/* why?
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3668kb

input:

3 6
...#..
......
#...##

output:

52

result:

ok 1 number(s): "52"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

2 2
..
..

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

2 2
#.
#.

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

4 5
###..
.###.
.##..
#...#

output:

34

result:

ok 1 number(s): "34"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3860kb

input:

11 12
.#######..##
.##..#.....#
#####..##.#.
#..##...#...
###..#..##..
####..###...
.#....##..##
.#####....##
.###..######
.######...##
#....##...##

output:

1674

result:

ok 1 number(s): "1674"

Test #6:

score: 0
Accepted
time: 87ms
memory: 3920kb

input:

50 45
####...#.#####..#..#.#########.##.#####..#..#
##.#.....#..#####....##..###...##.....##....#
##.#...####.##.#..#...####.#....##.###.......
...#...#..#..#.##.######...##..#...###..####.
##.....#.###.####.###..#....##..##..##.###...
..#.##.......##...##.........#..##.###.###...
###..##.###...###....

output:

496312

result:

ok 1 number(s): "496312"

Test #7:

score: 0
Accepted
time: 176ms
memory: 3960kb

input:

34 65
...............#####.#..##..############.....###....#..##########
.........#......#.......##..############.##..##........##########
..............#.......#.....##########..............##.##########
...##............#..............######.......#......#..##########
......#....#.....##......#.......

output:

279744

result:

ok 1 number(s): "279744"

Test #8:

score: 0
Accepted
time: 637ms
memory: 4180kb

input:

44 44
............................................
............................................
............................................
............................................
............................................
............................................
...........................

output:

936056

result:

ok 1 number(s): "936056"

Test #9:

score: 0
Accepted
time: 721ms
memory: 4184kb

input:

45 45
.............................................
.............................................
.............................................
.............................................
.............................................
.............................................
.....................

output:

999000

result:

ok 1 number(s): "999000"

Test #10:

score: 0
Accepted
time: 868ms
memory: 6032kb

input:

59 59
...#.......#.......#...#...#...................#...........
.#.#.#####.#.#####.#.#.#.#.#.#################.#.#########.
.#.#.#.....#.#...#.#.#.#.#.#.#...............#.#.#...#...#.
.#.#.#.#####.#.#.#.#.#.#.#.#.#.#############.#.#.#.#.#.#.#.
.#.#.#.#...#.#.#.#...#...#...#.#...#.........#...#.#.#...

output:

809100

result:

ok 1 number(s): "809100"

Test #11:

score: 0
Accepted
time: 1083ms
memory: 4244kb

input:

39 99
...#.......#...#...................#...#...#...#...#...........#...#.......#.......................
.#.#.#####.#.#.#.#################.#.#.#.#.#.#.#.#.#.#########.#.#.#.#####.#.#####################.
.#.#.....#.#.#.#.........#.........#.#.#.#.#.#.#.#.#.#...#.....#.#.#.#.....#.....#.......#...#...

output:

999000

result:

ok 1 number(s): "999000"

Test #12:

score: 0
Accepted
time: 1231ms
memory: 4288kb

input:

99 39
.......#.......#.......................
.#####.#.#####.#.#####################.
.....#.#.....#.#.#.......#.............
####.#.#####.#.#.#.#####.#.############
.....#.#.....#...#.#.....#.#...........
.#####.#.#########.#.#####.#.#########.
.....#.#.....#...#.#.....#.#.....#.....
####.#.#####.#...

output:

999000

result:

ok 1 number(s): "999000"

Test #13:

score: 0
Accepted
time: 742ms
memory: 5932kb

input:

45 45
#.......................................###..
.........................................##..
.............................................
.............................................
.............................................
.............................................
.....................

output:

999000

result:

ok 1 number(s): "999000"

Test #14:

score: -100
Wrong Answer
time: 111ms
memory: 4620kb

input:

132 453
###########################################################..####################..###################################################################.#################################################..############################..############################################################...

output:

1997915

result:

wrong answer 1st numbers differ - expected: '1000000', found: '1997915'