QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#328126#833. Cells BlockingzltAC ✓342ms19400kbC++143.8kb2024-02-15 17:27:272024-02-15 17:27:29

Judging History

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

  • [2024-02-15 17:27:29]
  • 评测
  • 测评结果:AC
  • 用时:342ms
  • 内存:19400kb
  • [2024-02-15 17:27:27]
  • 提交

answer

#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;

bool Mst;

const int maxn = 3030;

int n, m;
bitset<maxn> f[maxn], g[maxn], a[maxn], b[maxn];
char s[maxn][maxn];

const int mod = 11451419;

struct HashTable {
	int hd[mod + 3], len, nxt[maxn * maxn * 4];
	ll val[maxn * maxn * 4];
	
	inline void add(ll x) {
		int u = x % mod;
		for (int i = hd[u]; i; i = nxt[i]) {
			if (val[i] == x) {
				return;
			}
		}
		val[++len] = x;
		nxt[len] = hd[u];
		hd[u] = len;
	}
} mp;

void solve() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s[i] + 1);
	}
	f[1][1] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (s[i][j] == '*') {
				f[i][j] = 0;
			}
			if (f[i][j]) {
				f[i + 1][j] = f[i][j + 1] = 1;
			}
		}
	}
	g[n][m] = 1;
	for (int i = n; i; --i) {
		for (int j = m; j; --j) {
			if (s[i][j] == '*') {
				g[i][j] = 0;
			}
			if (g[i][j]) {
				g[i - 1][j] = g[i][j - 1] = 1;
			}
		}
	}
	if (!f[n][m]) {
		ll cnt = 0;
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				cnt += (s[i][j] == '.');
			}
		}
		printf("%lld\n", cnt * (cnt - 1) / 2);
		return;
	}
	int x = 1, y = 1;
	while (x < n || y < m) {
		a[x][y] = 1;
		if (x < n && f[x + 1][y] && g[x + 1][y]) {
			++x;
		} else {
			++y;
		}
	}
	a[n][m] = b[n][m] = 1;
	x = y = 1;
	while (x < n || y < m) {
		b[x][y] = 1;
		if (y < m && f[x][y + 1] && g[x][y + 1]) {
			++y;
		} else {
			++x;
		}
	}
	ll c1 = 0, c2 = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			c1 += (a[i][j] && b[i][j]);
			c2 += (s[i][j] == '.');
		}
	}
	ll ans = c1 * (c2 - 1) - c1 * (c1 - 1) / 2;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (a[i][j] && !b[i][j]) {
				int x = i, y = j;
				do {
					--x;
					++y;
				} while (!f[x][y] || !g[x][y]);
				if (!a[x][y] && b[x][y]) {
					mp.add(i + 10000LL * j + 100000000LL * x + 1000000000000LL * y);
				}
				int p = x, q = y;
				while (x > 1 || y > 1) {
					if (y > 1 && f[x][y - 1] && g[x][y - 1]) {
						--y;
					} else {
						--x;
					}
					if (!a[x][y] && b[x][y]) {
						mp.add(i + 10000LL * j + 100000000LL * x + 1000000000000LL * y);
					}
				}
				x = p;
				y = q;
				while (x < n || y < m) {
					if (x < n && f[x + 1][y] && g[x + 1][y]) {
						++x;
					} else {
						++y;
					}
					if (!a[x][y] && b[x][y]) {
						mp.add(i + 10000LL * j + 100000000LL * x + 1000000000000LL * y);
					}
				}
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (!a[i][j] && b[i][j]) {
				int x = i, y = j;
				do {
					++x;
					--y;
				} while (!f[x][y] || !g[x][y]);
				if (a[x][y] && !b[x][y]) {
					mp.add(x + 10000LL * y + 100000000LL * i + 1000000000000LL * j);
				}
				int p = x, q = y;
				while (x > 1 || y > 1) {
					if (x > 1 && f[x - 1][y] && g[x - 1][y]) {
						--x;
					} else {
						--y;
					}
					if (a[x][y] && !b[x][y]) {
						mp.add(x + 10000LL * y + 100000000LL * i + 1000000000000LL * j);
					}
				}
				x = p;
				y = q;
				while (x < n || y < m) {
					if (y < m && f[x][y + 1] && g[x][y + 1]) {
						++y;
					} else {
						++x;
					}
					if (a[x][y] && !b[x][y]) {
						mp.add(x + 10000LL * y + 100000000LL * i + 1000000000000LL * j);
					}
				}
			}
		}
	}
	ans += mp.len;
	printf("%lld\n", ans);
}

bool Med;

int main() {
	fprintf(stderr, "%.2lf MB\n", (&Mst - &Med) / 1048576.);
	int T = 1;
	// scanf("%d", &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: 7996kb

input:

3 3
...
...
...

output:

17

result:

ok 1 number(s): "17"

Test #2:

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

input:

3 3
.**
.*.
...

output:

15

result:

ok 1 number(s): "15"

Test #3:

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

input:

3 4
****
....
****

output:

6

result:

ok 1 number(s): "6"

Test #4:

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

input:

5 5
*....
.*.*.
*****
*.***
..*..

output:

66

result:

ok 1 number(s): "66"

Test #5:

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

input:

10 10
...***.*..
**...*.***
...***.*..
.**...*.*.
.*****..*.
..*.****.*
.**...****
..*..*.*.*
*.*.**....
....**...*

output:

1378

result:

ok 1 number(s): "1378"

Test #6:

score: 0
Accepted
time: 199ms
memory: 18584kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

17999999

result:

ok 1 number(s): "17999999"

Test #7:

score: 0
Accepted
time: 252ms
memory: 18252kb

input:

3000 3000
...................................................................................................................*......................................................................................................................................................................*..........

output:

17981671

result:

ok 1 number(s): "17981671"

Test #8:

score: 0
Accepted
time: 249ms
memory: 18240kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

17963615

result:

ok 1 number(s): "17963615"

Test #9:

score: 0
Accepted
time: 287ms
memory: 18984kb

input:

3000 3000
.........................................................................................................*...........................................................................................................................................................................................

output:

17945165

result:

ok 1 number(s): "17945165"

Test #10:

score: 0
Accepted
time: 314ms
memory: 18596kb

input:

3000 3000
......................................................................................................................................*........................................................................................................................................*.....................

output:

17928211

result:

ok 1 number(s): "17928211"

Test #11:

score: 0
Accepted
time: 297ms
memory: 19068kb

input:

3000 3000
...........................................*.........................................................................................................................................................................................................................................................

output:

17911522

result:

ok 1 number(s): "17911522"

Test #12:

score: 0
Accepted
time: 298ms
memory: 18036kb

input:

3000 3000
..............................*................................................................................................................*.....................................................................................................................................................

output:

17892283

result:

ok 1 number(s): "17892283"

Test #13:

score: 0
Accepted
time: 293ms
memory: 17476kb

input:

3000 3000
................................................................*....*................................................................................................................................................................................*..............................................

output:

17873837

result:

ok 1 number(s): "17873837"

Test #14:

score: 0
Accepted
time: 311ms
memory: 19076kb

input:

3000 3000
............................................................................................*.............................................................................*.....................................................................................................*....................

output:

17856701

result:

ok 1 number(s): "17856701"

Test #15:

score: 0
Accepted
time: 302ms
memory: 18804kb

input:

3000 3000
......................................*..........................................................................................................................................................*...................................................................................................

output:

17837857

result:

ok 1 number(s): "17837857"

Test #16:

score: 0
Accepted
time: 298ms
memory: 17464kb

input:

3000 3000
.................................................................................................................................................................................................................................*...................................................................

output:

17819731

result:

ok 1 number(s): "17819731"

Test #17:

score: 0
Accepted
time: 314ms
memory: 17440kb

input:

3000 3000
......**.....*.......*.*..........*..*...............**.............*.......*......*........*...*.....*.*.................*......*....*.........*....................*.................*.......................*.......*..*.*.......*.......................*..........*..*......................*...

output:

16202000

result:

ok 1 number(s): "16202000"

Test #18:

score: 0
Accepted
time: 342ms
memory: 18112kb

input:

3000 3000
..................*....*....*...*.*.............*.............*....*.*..*...*...*...*....*.................*...*.*.***...*....*......*.......**...*.......*.*...**...*...*...**.........*..........*.....*.*....*..*.......*.........*..*.....*...............**.......*.....*.*..*.*.*........*.....

output:

21600132

result:

ok 1 number(s): "21600132"

Test #19:

score: 0
Accepted
time: 82ms
memory: 16268kb

input:

3000 3000
..*.**...*...............*........*.*..*.*.....*........*.*..........***..*..*..*..*.*....*...*.*.....***.*...*........*..*.****..*.*....**.......*......*....*..*......*......*..*..*.*..*....*..**.*.......**.*...*....**.....**..*......*...*....*..*.**.*..***...*.....*....***.*........*.......

output:

19862779430431

result:

ok 1 number(s): "19862779430431"

Test #20:

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

input:

3000 3000
.**.**..***....*.*....*..*...*.**.**.**.......*...*........*.**.*...*...**..*...*.*.**.*.*.*.*..*...*.....*.*.**.*.*....*.**.....*..**.**.*....**.**.**..*..**...*...***.**.*.*......**.**.*...****.....***.*..*.**.*......*..**.**.**.....**...*.*..***.******...**....****..***..**.*........*.....

output:

14601805246666

result:

ok 1 number(s): "14601805246666"

Test #21:

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

input:

1 1
*

output:

0

result:

ok 1 number(s): "0"

Test #22:

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

input:

1 1
.

output:

0

result:

ok 1 number(s): "0"

Test #23:

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

input:

2 2
..
..

output:

6

result:

ok 1 number(s): "6"

Test #24:

score: 0
Accepted
time: 108ms
memory: 16496kb

input:

3000 3000
.***..**..*.*.*..*...**.*.**...***.....*..***.***.***.*..***.*......*.**.***.***.*...**.*.*..***.*..*.**..***.....*.*...***.*.***.*...*.*.....***.*..**...*.*..*.******.*.*...**.*..**.**.**.*.**..***.**.***..*......**.***.**.*....*..*.....*...*..*.*..*..*.*...**.**...*..**..***.**..*....*.....

output:

10151159625145

result:

ok 1 number(s): "10151159625145"

Test #25:

score: 0
Accepted
time: 40ms
memory: 16120kb

input:

3000 3000
*******************************************************************************************************************************************************************************************************************************************************.******************************************...

output:

39716328

result:

ok 1 number(s): "39716328"

Test #26:

score: 0
Accepted
time: 249ms
memory: 18344kb

input:

3000 3000
..*..................................................................................................................................................................................................................................................................................................

output:

35988321

result:

ok 1 number(s): "35988321"

Test #27:

score: 0
Accepted
time: 244ms
memory: 18456kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

35981866

result:

ok 1 number(s): "35981866"

Test #28:

score: 0
Accepted
time: 225ms
memory: 17716kb

input:

3000 3000
...**................................................................................................................................................................................................................................................................................................

output:

17988153

result:

ok 1 number(s): "17988153"

Test #29:

score: 0
Accepted
time: 230ms
memory: 18248kb

input:

3000 3000
...*.*...............................................................................................................................................................................................................................................................................................

output:

35969654

result:

ok 1 number(s): "35969654"

Test #30:

score: 0
Accepted
time: 259ms
memory: 17976kb

input:

3000 3000
..*..................................................................................................................................................................................................................................................................................................

output:

17982216

result:

ok 1 number(s): "17982216"

Test #31:

score: 0
Accepted
time: 247ms
memory: 18060kb

input:

3000 3000
....**.*.............................................................................................................................................................................................................................................................................................

output:

71916090

result:

ok 1 number(s): "71916090"

Test #32:

score: 0
Accepted
time: 246ms
memory: 18680kb

input:

3000 3000
....****.............................................................................................................................................................................................................................................................................................

output:

71903186

result:

ok 1 number(s): "71903186"

Test #33:

score: 0
Accepted
time: 250ms
memory: 19400kb

input:

3000 3000
.........*...........................................................................................................................................................................................................................................................................................

output:

17973051

result:

ok 1 number(s): "17973051"

Test #34:

score: 0
Accepted
time: 234ms
memory: 17672kb

input:

3000 3000
.*.......*.............................................................................................................*................................................................................*............................................................................................

output:

35630636

result:

ok 1 number(s): "35630636"

Test #35:

score: 0
Accepted
time: 243ms
memory: 18956kb

input:

3000 3000
.**...........................*..........................................................................................................................................*...........................................................................................................................

output:

44529907

result:

ok 1 number(s): "44529907"

Test #36:

score: 0
Accepted
time: 260ms
memory: 18236kb

input:

3000 3000
....*................................................................................................................................................................................................................................................................................................

output:

53426863

result:

ok 1 number(s): "53426863"

Test #37:

score: 0
Accepted
time: 251ms
memory: 18212kb

input:

3000 3000
..*.*........................................................................*............................*...............*.............................................................................................................................................*........*...................

output:

53419301

result:

ok 1 number(s): "53419301"

Test #38:

score: 0
Accepted
time: 250ms
memory: 18180kb

input:

3000 3000
......*.........*...................................................................................*.....................................................................................................................*................................................*.........................

output:

26705269

result:

ok 1 number(s): "26705269"

Test #39:

score: 0
Accepted
time: 250ms
memory: 19264kb

input:

3000 3000
....*.**....*................*............................*..........*...............................................................................................................................................................................................................................

output:

17799069

result:

ok 1 number(s): "17799069"

Test #40:

score: 0
Accepted
time: 247ms
memory: 17508kb

input:

3000 3000
...***.......................................*...........*.....................*........*...........................................................................................................................................................*................................................

output:

53393629

result:

ok 1 number(s): "53393629"

Test #41:

score: 0
Accepted
time: 235ms
memory: 17624kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

98852811

result:

ok 1 number(s): "98852811"

Test #42:

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

input:

1 3000
........................................................................................................................................................................................................................................................................................................

output:

4498500

result:

ok 1 number(s): "4498500"

Test #43:

score: 0
Accepted
time: 246ms
memory: 17520kb

input:

3000 3000
.*.....*...........................................................................................................*...................................*........................................................................................*............*.......................................

output:

88979547

result:

ok 1 number(s): "88979547"

Test #44:

score: 0
Accepted
time: 244ms
memory: 18836kb

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:

35964327

result:

ok 1 number(s): "35964327"