QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#331468#833. Cells Blockingsinsop90WA 388ms162108kbC++142.3kb2024-02-18 10:52:042024-02-18 10:52:04

Judging History

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

  • [2024-02-18 10:52:04]
  • 评测
  • 测评结果:WA
  • 用时:388ms
  • 内存:162108kb
  • [2024-02-18 10:52:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
char s[maxn][maxn];
int vis1[maxn][maxn], vis2[maxn][maxn], vis3[maxn][maxn], n, m, cnt, rot[maxn][maxn], ans;
bool visS[maxn][maxn], visT[maxn][maxn];
vector<pair<int, int>> vec;
bool check(int x, int y) {
	return (x >= 1 && x <= n && y >= 1 && y <= m && s[x][y] == '.');
}
void dfs1(int x, int y) {
	visS[x][y] = 1;
	if(x == n && y == m) return;
	if(check(x + 1, y) && !vis1[x + 1][y]) {
		vis1[x + 1][y] = 1;
		dfs1(x + 1, y); 
	}
	if(check(x, y + 1) && !vis1[x][y + 1]) {
		vis1[x][y + 1] = 2;
		dfs1(x, y + 1);
	}
}
void dfs2(int x, int y) {
	visT[x][y] = 1;
	if(x == 1 && y == 1) return;
	if(check(x, y - 1) && !vis2[x][y - 1]) {
		vis2[x][y - 1] = 2;
		dfs2(x, y - 1);
	}
	if(check(x - 1, y) && !vis2[x - 1][y]) {
		vis2[x - 1][y] = 1;
		dfs2(x - 1, y);
	}
}
void dfs3(int x, int y) {
	if(x == n && y == m) return;
	if(check(x, y + 1) && !vis3[x][y + 1]) {
		vis3[x][y + 1] = 2;
		dfs3(x, y + 1);
	}
	if(check(x + 1, y) && !vis3[x + 1][y]) {
		vis3[x + 1][y] = 1;
		dfs3(x + 1, y); 
	}
	
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for(int i = 1;i <= n;i++) {
		cin >> s[i] + 1;
		for(int j = 1;j <= m;j++) cnt += (s[i][j] == '.');
	}
	dfs1(1, 1);
	if(!visS[n][m]) {
		cout << cnt * (cnt - 1) / 2 << '\n';
		return 0;
	}
	dfs2(n, m);
	dfs3(1, 1);
	int X = n, Y = m, res = 1;
	while(!(X == 1 && Y == 1)) {
		rot[X][Y] = 1;
		if(vis3[X][Y] == 1) X --;
		else Y --;
	}
	X = n, Y = m;
	while(!(X == 1 && Y == 1)) {
		vec.push_back(make_pair(X, Y));
		res += rot[X][Y];
		if(vis1[X][Y] == 1) X --;
		else Y --;
	}
	vec.push_back(make_pair(1, 1));
	ans = res * (cnt - res) + res * (res - 1) / 2;
	for(pair<int, int> t : vec) {
		int X = t.first, Y = t.second, resN = 0;
		while(X >= 1 && Y <= m) {
			X --, Y ++;
			if(visS[X][Y] && visT[X][Y]) break;
		}
		if(!(X >= 1 && Y <= m)) continue;
		int XX = X, YY = Y;
		while(!(XX == 1 && YY == 1)) {
			resN += rot[XX][YY];
			if(vis1[XX][YY] == 1) XX --;
			else YY --;
		}
		XX = X, YY = Y;
		if(vis2[XX][YY] == 1) XX ++;
		else YY ++;
		while(!(XX == n && YY == m)) {
			resN += rot[XX][YY];
			if(vis2[XX][YY] == 1) XX ++;
			else YY ++;
		}
		ans += resN;
	}
	cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 3
...
...
...

output:

17

result:

ok 1 number(s): "17"

Test #2:

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

input:

3 3
.**
.*.
...

output:

15

result:

ok 1 number(s): "15"

Test #3:

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

input:

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

output:

6

result:

ok 1 number(s): "6"

Test #4:

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

input:

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

output:

66

result:

ok 1 number(s): "66"

Test #5:

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

input:

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

output:

1378

result:

ok 1 number(s): "1378"

Test #6:

score: 0
Accepted
time: 388ms
memory: 162108kb

input:

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

output:

17999999

result:

ok 1 number(s): "17999999"

Test #7:

score: 0
Accepted
time: 367ms
memory: 161916kb

input:

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

output:

17981671

result:

ok 1 number(s): "17981671"

Test #8:

score: 0
Accepted
time: 375ms
memory: 160732kb

input:

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

output:

17963615

result:

ok 1 number(s): "17963615"

Test #9:

score: 0
Accepted
time: 377ms
memory: 159272kb

input:

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

output:

17945165

result:

ok 1 number(s): "17945165"

Test #10:

score: 0
Accepted
time: 379ms
memory: 157856kb

input:

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

output:

17928211

result:

ok 1 number(s): "17928211"

Test #11:

score: 0
Accepted
time: 370ms
memory: 157892kb

input:

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

output:

17911522

result:

ok 1 number(s): "17911522"

Test #12:

score: 0
Accepted
time: 368ms
memory: 159256kb

input:

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

output:

17892283

result:

ok 1 number(s): "17892283"

Test #13:

score: 0
Accepted
time: 354ms
memory: 160668kb

input:

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

output:

17873837

result:

ok 1 number(s): "17873837"

Test #14:

score: 0
Accepted
time: 358ms
memory: 159172kb

input:

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

output:

17856701

result:

ok 1 number(s): "17856701"

Test #15:

score: 0
Accepted
time: 348ms
memory: 160520kb

input:

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

output:

17837857

result:

ok 1 number(s): "17837857"

Test #16:

score: 0
Accepted
time: 336ms
memory: 160580kb

input:

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

output:

17819731

result:

ok 1 number(s): "17819731"

Test #17:

score: 0
Accepted
time: 346ms
memory: 159428kb

input:

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

output:

16202000

result:

ok 1 number(s): "16202000"

Test #18:

score: -100
Wrong Answer
time: 287ms
memory: 153808kb

input:

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

output:

21606128

result:

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