QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#328208#833. Cells BlockingTerdyWA 666ms245732kbC++141.4kb2024-02-15 18:15:452024-02-15 18:15:45

Judging History

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

  • [2024-02-15 18:15:45]
  • 评测
  • 测评结果:WA
  • 用时:666ms
  • 内存:245732kb
  • [2024-02-15 18:15:45]
  • 提交

answer

# include <bits/stdc++.h>

using namespace std;

# define int long long

const int N = 3e3 + 5;
int n , m , cnt , ans , f[N][N] , g[N][N];
char mp[N][N];
vector< int > vec[N<<1];

signed main()
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> mp[i][j] , cnt += mp[i][j] == '.';
	f[1][1] = mp[1][1] == '.';
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) if(mp[i][j] == '.') f[i][j] |= f[i][j - 1] | f[i - 1][j];
	g[n][m] = mp[n][m] == '.';
	for(int i = n; i; i--) for(int j = m; j; j--) if(mp[i][j] == '.') g[i][j] |= g[i][j + 1] | g[i + 1][j];
	if(!f[n][m]) return cout << cnt * (cnt - 1) / 2 , 0;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) if(f[i][j] && g[i][j]) vec[i + j].push_back(i); else mp[i][j] = '*';
	for(int i = 2; i <= n + m; i++) if(vec[i].size() == 1) ans += --cnt;
	for(int i = 2; i <= n + m; i++)
	{
		auto &v = vec[i];
		if(v.size() == 1) continue ;
		int l = v[1] , r = v[v.size() - 1];
		if(l == r) ans++;
		for(int j = i + 1; j <= n + m; j++)
		{
			if(mp[l][j - l] == '*') l++;
			if(mp[r + 1][j - (r + 1)] == '.') r++;
			if(l == r && vec[j].size() > 1) ans++;
		}
		l = v[0] , r = v[v.size() - 2];
		for(int j = i + 1; j <= n + m; j++)
		{
			if(mp[l][j - l] == '*') l++;
			if(mp[r + 1][j - (r + 1)] == '.') r++;
			if(l == r && vec[j].size() > 1) ans++;
		}
	}
	cout << ans;
	return 0;
}
/*
3 3
...
...
...
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3688kb

input:

3 3
...
...
...

output:

17

result:

ok 1 number(s): "17"

Test #2:

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

input:

3 3
.**
.*.
...

output:

15

result:

ok 1 number(s): "15"

Test #3:

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

input:

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

output:

6

result:

ok 1 number(s): "6"

Test #4:

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

input:

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

output:

66

result:

ok 1 number(s): "66"

Test #5:

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

input:

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

output:

1378

result:

ok 1 number(s): "1378"

Test #6:

score: 0
Accepted
time: 530ms
memory: 245488kb

input:

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

output:

17999999

result:

ok 1 number(s): "17999999"

Test #7:

score: 0
Accepted
time: 578ms
memory: 245732kb

input:

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

output:

17981671

result:

ok 1 number(s): "17981671"

Test #8:

score: 0
Accepted
time: 634ms
memory: 245492kb

input:

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

output:

17963615

result:

ok 1 number(s): "17963615"

Test #9:

score: 0
Accepted
time: 666ms
memory: 245088kb

input:

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

output:

17945165

result:

ok 1 number(s): "17945165"

Test #10:

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

input:

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

output:

17928211

result:

ok 1 number(s): "17928211"

Test #11:

score: 0
Accepted
time: 652ms
memory: 244596kb

input:

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

output:

17911522

result:

ok 1 number(s): "17911522"

Test #12:

score: 0
Accepted
time: 625ms
memory: 244632kb

input:

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

output:

17892283

result:

ok 1 number(s): "17892283"

Test #13:

score: 0
Accepted
time: 666ms
memory: 244408kb

input:

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

output:

17873837

result:

ok 1 number(s): "17873837"

Test #14:

score: 0
Accepted
time: 659ms
memory: 243752kb

input:

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

output:

17856701

result:

ok 1 number(s): "17856701"

Test #15:

score: 0
Accepted
time: 633ms
memory: 243744kb

input:

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

output:

17837857

result:

ok 1 number(s): "17837857"

Test #16:

score: 0
Accepted
time: 627ms
memory: 242860kb

input:

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

output:

17819731

result:

ok 1 number(s): "17819731"

Test #17:

score: 0
Accepted
time: 621ms
memory: 215004kb

input:

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

output:

16202000

result:

ok 1 number(s): "16202000"

Test #18:

score: -100
Wrong Answer
time: 577ms
memory: 184600kb

input:

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

output:

21600125

result:

wrong answer 1st numbers differ - expected: '21600132', found: '21600125'