QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#328041#833. Cells BlockingEnder32kAC ✓754ms231164kbC++173.6kb2024-02-15 16:27:082024-02-15 16:27:10

Judging History

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

  • [2024-02-15 16:27:10]
  • 评测
  • 测评结果:AC
  • 用时:754ms
  • 内存:231164kb
  • [2024-02-15 16:27:08]
  • 提交

answer

#include <bits/stdc++.h>
#define eb emplace_back
#define pb pop_back
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef tuple<int, int, int> tu;
bool Mbe;

const int N = 3e3 + 300;

char tc[N];
int fx[4][2] = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
int n, m, s, cup, c[N][N], ct[N][N], a[N][N], ds[N][N], dt[N][N], vl[N][N], vr[N][N], pos[N << 1];
vector<pi> L, R;

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> (tc + 1);
		for (int j = 1; j <= m; j++)
			a[i][j] = (tc[j] == '.' ? 1 : 0), s += a[i][j];
	}
	ds[1][1] = a[1][1], dt[n][m] = a[n][m];
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (i == 1 && j == 1) continue;
			if (!a[i][j]) ds[i][j] = 0;
			else ds[i][j] = ds[i - 1][j] | ds[i][j - 1];
		}
	}
	for (int i = n; i; i--) {
		for (int j = m; j; j--) {
			if (i == n && j == m) continue;
			if (!a[i][j]) dt[i][j] = 0;
			else dt[i][j] = dt[i][j + 1] | dt[i + 1][j];
		}
	}
	if (!ds[n][m]) return cout << 1ll * s * (s - 1) / 2 << '\n', void();
	ll res = 0;
	pi cur = mp(1, 1); L.eb(cur);
	while (cur.fi != n || cur.se != m) {
		auto &[i, j] = cur;
		dt[i + 1][j] ? (i++) : (j++);
		L.eb(cur = mp(i, j));
	}
	cur = mp(1, 1), R.eb(cur);
	while (cur.fi != n || cur.se != m) {
		auto &[i, j] = cur;
		dt[i][j + 1] ? (j++) : (i++);
		R.eb(cur = mp(i, j));
	}
	for (auto [x, y] : L) vl[x][y] = 1;
	for (auto [x, y] : R) vr[x][y] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (vl[i][j] && vr[i][j]) cup++;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (vl[i][j] && vr[i][j]) res += s - 1;
			else if (a[i][j] && !vl[i][j] && !vr[i][j]) res += cup;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (vl[i][j] && !vr[i][j] && pos[i + j]) 
				c[pos[i + j]][i + j - pos[i + j]]++;
			if (ds[i][j] && dt[i][j]) pos[i + j] = i;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (!c[i][j]) continue;
			cur = mp(i, j), ct[i][j] += c[i][j];
			while (cur.fi != 1 || cur.se != 1) {
				auto &[x, y] = cur; 
				ds[x][y - 1] ? (y--) : (x--);
				ct[x][y] += c[i][j], cur = mp(x, y);
			}
			cur = mp(i, j);
			while (cur.fi != n || cur.se != m) {
				auto &[x, y] = cur;
				dt[x + 1][y] ? (x++) : (y++);
				ct[x][y] += c[i][j], cur = mp(x, y);
			}
		}
	}
	for (auto [x, y] : R) res += ct[x][y];
	memset(c, 0, sizeof(c));
	memset(ct, 0, sizeof(ct));
	memset(pos, 0, sizeof(pos));
	for (int i = n; i; i--) {
		for (int j = m; j; j--) {
			if (!vl[i][j] && vr[i][j] && pos[i + j])
				c[pos[i + j]][i + j - pos[i + j]]++;
			if (ds[i][j] && dt[i][j]) pos[i + j] = i;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (!c[i][j]) continue;
			cur = mp(i, j), ct[i][j] += c[i][j];
			while (cur.fi != 1 || cur.se != 1) {
				auto &[x, y] = cur; 
				ds[x - 1][y] ? (x--) : (y--);
				ct[x][y] += c[i][j], cur = mp(x, y);
			}
			cur = mp(i, j);
			while (cur.fi != n || cur.se != m) {
				auto &[x, y] = cur;
				dt[x][y + 1] ? (y++) : (x++);
				ct[x][y] += c[i][j], cur = mp(x, y);
			}
		}
	}
	for (auto [x, y] : L) res += ct[x][y];
	cout << res / 2 << '\n';
}

bool Med;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cerr << (&Mbe - &Med) / 1048576.0 << " MB\n";
	#ifdef FILE
		freopen("1.in", "r", stdin);
		freopen("1.out", "w", stdout);
	#endif
	int T = 1;
	// cin >> T;
	while (T--) solve();
	cerr << (int)(1e3 * clock() / CLOCKS_PER_SEC) << " ms\n";
	return 0;
}

詳細信息

Test #1:

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

input:

3 3
...
...
...

output:

17

result:

ok 1 number(s): "17"

Test #2:

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

input:

3 3
.**
.*.
...

output:

15

result:

ok 1 number(s): "15"

Test #3:

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

input:

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

output:

6

result:

ok 1 number(s): "6"

Test #4:

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

input:

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

output:

66

result:

ok 1 number(s): "66"

Test #5:

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

input:

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

output:

1378

result:

ok 1 number(s): "1378"

Test #6:

score: 0
Accepted
time: 735ms
memory: 229884kb

input:

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

output:

17999999

result:

ok 1 number(s): "17999999"

Test #7:

score: 0
Accepted
time: 728ms
memory: 231068kb

input:

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

output:

17981671

result:

ok 1 number(s): "17981671"

Test #8:

score: 0
Accepted
time: 725ms
memory: 230024kb

input:

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

output:

17963615

result:

ok 1 number(s): "17963615"

Test #9:

score: 0
Accepted
time: 730ms
memory: 230780kb

input:

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

output:

17945165

result:

ok 1 number(s): "17945165"

Test #10:

score: 0
Accepted
time: 733ms
memory: 230216kb

input:

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

output:

17928211

result:

ok 1 number(s): "17928211"

Test #11:

score: 0
Accepted
time: 732ms
memory: 229416kb

input:

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

output:

17911522

result:

ok 1 number(s): "17911522"

Test #12:

score: 0
Accepted
time: 732ms
memory: 231164kb

input:

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

output:

17892283

result:

ok 1 number(s): "17892283"

Test #13:

score: 0
Accepted
time: 751ms
memory: 230324kb

input:

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

output:

17873837

result:

ok 1 number(s): "17873837"

Test #14:

score: 0
Accepted
time: 747ms
memory: 230492kb

input:

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

output:

17856701

result:

ok 1 number(s): "17856701"

Test #15:

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

input:

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

output:

17837857

result:

ok 1 number(s): "17837857"

Test #16:

score: 0
Accepted
time: 729ms
memory: 230316kb

input:

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

output:

17819731

result:

ok 1 number(s): "17819731"

Test #17:

score: 0
Accepted
time: 744ms
memory: 229324kb

input:

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

output:

16202000

result:

ok 1 number(s): "16202000"

Test #18:

score: 0
Accepted
time: 743ms
memory: 230344kb

input:

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

output:

21600132

result:

ok 1 number(s): "21600132"

Test #19:

score: 0
Accepted
time: 86ms
memory: 120032kb

input:

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

output:

19862779430431

result:

ok 1 number(s): "19862779430431"

Test #20:

score: 0
Accepted
time: 95ms
memory: 120640kb

input:

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

output:

14601805246666

result:

ok 1 number(s): "14601805246666"

Test #21:

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

input:

1 1
*

output:

0

result:

ok 1 number(s): "0"

Test #22:

score: 0
Accepted
time: 4ms
memory: 97232kb

input:

1 1
.

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 4ms
memory: 98804kb

input:

2 2
..
..

output:

6

result:

ok 1 number(s): "6"

Test #24:

score: 0
Accepted
time: 67ms
memory: 121524kb

input:

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

output:

10151159625145

result:

ok 1 number(s): "10151159625145"

Test #25:

score: 0
Accepted
time: 35ms
memory: 120544kb

input:

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

output:

39716328

result:

ok 1 number(s): "39716328"

Test #26:

score: 0
Accepted
time: 717ms
memory: 229704kb

input:

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

output:

35988321

result:

ok 1 number(s): "35988321"

Test #27:

score: 0
Accepted
time: 718ms
memory: 229860kb

input:

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

output:

35981866

result:

ok 1 number(s): "35981866"

Test #28:

score: 0
Accepted
time: 754ms
memory: 230108kb

input:

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

output:

17988153

result:

ok 1 number(s): "17988153"

Test #29:

score: 0
Accepted
time: 717ms
memory: 230188kb

input:

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

output:

35969654

result:

ok 1 number(s): "35969654"

Test #30:

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

input:

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

output:

17982216

result:

ok 1 number(s): "17982216"

Test #31:

score: 0
Accepted
time: 737ms
memory: 229516kb

input:

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

output:

71916090

result:

ok 1 number(s): "71916090"

Test #32:

score: 0
Accepted
time: 711ms
memory: 230948kb

input:

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

output:

71903186

result:

ok 1 number(s): "71903186"

Test #33:

score: 0
Accepted
time: 706ms
memory: 229620kb

input:

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

output:

17973051

result:

ok 1 number(s): "17973051"

Test #34:

score: 0
Accepted
time: 717ms
memory: 230256kb

input:

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

output:

35630636

result:

ok 1 number(s): "35630636"

Test #35:

score: 0
Accepted
time: 720ms
memory: 229752kb

input:

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

output:

44529907

result:

ok 1 number(s): "44529907"

Test #36:

score: 0
Accepted
time: 752ms
memory: 230692kb

input:

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

output:

53426863

result:

ok 1 number(s): "53426863"

Test #37:

score: 0
Accepted
time: 711ms
memory: 230640kb

input:

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

output:

53419301

result:

ok 1 number(s): "53419301"

Test #38:

score: 0
Accepted
time: 725ms
memory: 229864kb

input:

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

output:

26705269

result:

ok 1 number(s): "26705269"

Test #39:

score: 0
Accepted
time: 724ms
memory: 230432kb

input:

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

output:

17799069

result:

ok 1 number(s): "17799069"

Test #40:

score: 0
Accepted
time: 725ms
memory: 229676kb

input:

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

output:

53393629

result:

ok 1 number(s): "53393629"

Test #41:

score: 0
Accepted
time: 726ms
memory: 229704kb

input:

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

output:

98852811

result:

ok 1 number(s): "98852811"

Test #42:

score: 0
Accepted
time: 4ms
memory: 97244kb

input:

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

output:

4498500

result:

ok 1 number(s): "4498500"

Test #43:

score: 0
Accepted
time: 741ms
memory: 229548kb

input:

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

output:

88979547

result:

ok 1 number(s): "88979547"

Test #44:

score: 0
Accepted
time: 747ms
memory: 230352kb

input:

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

output:

35964327

result:

ok 1 number(s): "35964327"