QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#468052#1978. Stabbing NumberSkyMathsAC ✓4ms3960kbC++142.0kb2024-07-08 19:00:502024-07-08 19:00:51

Judging History

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

  • [2024-07-08 19:00:51]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3960kb
  • [2024-07-08 19:00:50]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,l,r) for (register int i(l), i##end(r); i <= i##end; ++i)
#define per(i,r,l) for (register int i(r), i##end(l); i >= i##end; --i)
#define LL long long
using namespace std;

template <typename T>
inline void read(T &x) {
	x = 0; bool f = 0; char ch = getchar();
	while (ch < '0' || ch > '9') {
		f ^= ch == '-';
		ch = getchar();
	}
	while (ch <= '9' && ch >= '0') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	if (f) x = -x;
}

template <typename Tx, typename ...Ty>
inline void read(Tx &x, Ty &...y) {
	read(x);
	read(y...);
}

template <typename T>
inline void cmin(T &x, T y) {
	if (x > y) x = y;
}
template <typename T>
inline void cmax(T &x, T y) {
	if (x < y) x = y;
}

const int N = 59;
int n, m, ans(N);
int h[N], id[N];
char a[N][N];

int vis[N][N];

int calc() {
	memset(vis, 0, sizeof(vis));
	rep (i, 1, m) {
		int x = id[i];
		int L, R;
		L = R = x;
		while (L > 1 && h[L - 1] >= h[x] && !vis[h[x]][L - 1]) --L;
		while (R < m && h[R + 1] >= h[x] && !vis[h[x]][R + 1]) ++R;
		per (j, h[x], 1) {
			if (!vis[j][x]) {
				rep (k, L, R) {
					vis[j][k] = x;
				}
			}
		}
	}
	int res = 0;
	rep (i, 1, n + 1) {
		int sum = 0;
		rep (j, 1, m + 1) {
			if (vis[i][j] == 0) {
				cmax(res, sum);
				sum = 0;
			}
			else {
				if (vis[i][j] != vis[i][j - 1]) {
					++sum;
				}
			}
		}
	}
	rep (j, 1, m + 1) {
		int sum = 0;
		rep (i, 1, n + 1) {
			if (vis[i][j] == 0) {
				cmax(res, sum);
				sum = 0;
			}
			else {
				if (vis[i][j] != vis[i - 1][j]) {
					++sum;
				}
			}
		}
	}
	return res;
}

int main() {
	read(n, m);
	rep (i, 1, n) {
		rep (j, 1, m) {
			scanf(" %c", &a[i][j]);
		}
	}
	rep (j, 1, m) {
		rep (i, 1, n) {
			if (a[i][j] == '*') {
				h[j] = n - i + 1;
				break;
			}
		}
	}
	m = unique(h, h + m + 1) - h - 1;
	if (h[m] == 0) --m;
//	rep (i, 1, m) printf("%d ", h[i]);
	rep (i, 1, m) id[i] = i;
	do {
		cmin(ans, calc());
	} while (next_permutation(id + 1, id + m + 1));
	printf("%d\n", ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

10 13
.....****....
.....*..*....
.....*..***..
.....*....*..
.....*....***
...***......*
...*........*
****........*
*...........*
*************

output:

2

result:

ok single line: '2'

Test #2:

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

input:

8 15
...............
.........*****.
....***..*...*.
....*.*..*...*.
.****.****...*.
.*...........*.
.*************.
...............

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3804kb

input:

16 25
...............**********
...............*........*
............****........*
............*...........*
..........***...........*
..........*.............*
........***.............*
........*...............*
.....****...............*
.....*..................*
.....*..................*
...***.....

output:

3

result:

ok single line: '3'

Test #4:

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

input:

13 25
........******...........
........*....*...........
.....****....*...........
.....*.......****........
.....*..........*........
.....*..........****.....
.....*.............*.....
.....*.............******
...***..................*
...*....................*
****....................*
*..........

output:

3

result:

ok single line: '3'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3892kb

input:

13 25
........******...........
........*....*...........
.....****....****........
.....*..........*........
.....*..........*........
.....*..........*........
.....*..........*........
.....*..........*........
...***..........*****....
...*................*....
****................*****
*..........

output:

3

result:

ok single line: '3'

Test #6:

score: 0
Accepted
time: 2ms
memory: 3824kb

input:

8 24
.........****....*******
...****..*..*....*.....*
...*..*..*..*..***.....*
****..*..*..*..*.......*
*.....****..*..*.......*
*...........****.......*
*......................*
************************

output:

2

result:

ok single line: '2'

Test #7:

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

input:

10 24
...............****.....
.........****..*..*.....
...****..*..*..*..*.....
...*..*..*..*..*..*.....
****..*..*..*..*..*.....
*.....****..*..*..*.....
*...........****..*.....
*.................******
*......................*
************************

output:

3

result:

ok single line: '3'

Test #8:

score: 0
Accepted
time: 2ms
memory: 3872kb

input:

14 25
........******...........
........*....*...........
.....****....*...........
.....*.......*...........
.....*.......*****.......
.....*...........*.......
...***...........*.......
...*.............*.......
...*.............****....
...*................*....
****................*....
*..........

output:

3

result:

ok single line: '3'

Test #9:

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

input:

20 20
....................
....................
....................
....................
....................
....................
....................
....................
....................
.**************.....
.*............*.....
.*............*.....
.*............*.....
.**************.....
...

output:

1

result:

ok single line: '1'

Test #10:

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

input:

20 20
....................
....................
....................
....................
......*********.....
......*.......*.....
......*.......*.....
......*.......*.....
......*.......*.....
......*.......*.....
......*.......*.....
......*.......*.....
......*.......*.....
......*.......******
...

output:

2

result:

ok single line: '2'

Test #11:

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

input:

20 20
....................
....................
....................
......****..........
......*..*..........
......*..*..........
......*..*..........
......*..*..........
......*..*..........
......*..*..........
......*..*..........
......*..*..........
......*..*..........
......*..*..........
...

output:

2

result:

ok single line: '2'

Test #12:

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

input:

20 20
....................
....................
....................
.****...............
.*..*...............
.*..*.......*****...
.*..*.......*...*...
.*..*****...*...*...
.*......*...*...*...
.*......*...*...*...
.*......*...*...*...
.*......*...*...*...
.*......*...*...*...
.*......*...*...*...
...

output:

2

result:

ok single line: '2'

Test #13:

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

input:

40 40
........................................
..............******....................
..............*....*....................
..............*....*....................
..............*....*....................
..............*....*....................
..............*....*....................
..........

output:

2

result:

ok single line: '2'

Test #14:

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

input:

40 40
..........*****.........................
..........*...*.........................
..........*...*.........................
..........*...*.........................
......*****...*.........................
......*.......*.........................
......*.......*.........******..........
......*...

output:

2

result:

ok single line: '2'

Test #15:

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

input:

40 40
.................*****..................
.................*...*.......***........
.................*...*.......*.*........
.................*...*.......*.*........
.................*...*.......*.*........
.................*...*.......*.*........
.................*...*.......*.*........
..........

output:

3

result:

ok single line: '3'

Test #16:

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

input:

40 40
...............******...................
...............*....*...................
...............*....*...................
...............*....*...................
...............*....*...................
...............*....*...................
...............*....*...................
..........

output:

2

result:

ok single line: '2'

Test #17:

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

input:

40 40
.....................****...............
.....................*..*.***...........
.............***.....*..*.*.*...........
.............*.*.....*..*.*.*...........
.............*.*.....*..*.*.*...........
.............*.*.***.*..*.*.*...........
.............*.*.*.*.*..*.*.*...........
..........

output:

3

result:

ok single line: '3'

Test #18:

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

input:

40 40
........................................
........................................
........................................
........................................
........................................
........................................
........................................
..........

output:

3

result:

ok single line: '3'