QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#467898 | #8659. Sheba’s Amoebas | Bahnasy# | AC ✓ | 1ms | 3752kb | C++20 | 1.2kb | 2024-07-08 18:13:50 | 2024-07-08 18:13:50 |
Judging History
answer
// #pragma GCC target("avx2,avx512f,avx512vl,avx512bw,avx512dq,avx512cd,avx512vbmi,avx512vbmi2,avx512vpopcntdq,avx512bitalg,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
char arr[105][105];
bool vis[105][105];
int n, m;
bool check(int x, int y) {
return (x > 0 && x <= n && y > 0 && y <= m);
}
void dfs(int x, int y) {
if (vis[x][y])return;
vis[x][y] = true;
for (int i = -1; i < 2; i++) {
for (int j = -1; j < 2; j++) {
if (j == 0 && i == 0)continue;
int xx = x + i;
int yy = y + j;
if (check(xx, yy) && !vis[xx][yy]&&arr[xx][yy]=='#') {
dfs(xx, yy);
}
}
}
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {cin >> arr[i][j];}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (arr[i][j] == '#' && !vis[i][j]) {
ans++;
dfs(i, j);
}
}
}
cout << ans << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
input:
12 12 .##########. #..........# #..#...##..# #.##..#..#.# #......#.#.# #....#..#..# #...#.#....# #..#...#...# .#..#.#....# #....#.....# #.........#. .#########..
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
12 10 .#####.... #.....#... #..#..#... #.#.#.#... #..#..#... .#...#.... ..###..... ......#... .##..#.#.. #..#..#... .##....... ..........
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
6 6 .####. #....# #....# #....# #....# .####.
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
3 3 .#. #.# .#.
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
10 10 .#...#.... #.#.#.#... .#...#..#. ...#...#.# ..#.#...#. ...#..#... .#...#.#.. #.#...#... .#........ ..........
output:
6
result:
ok single line: '6'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
3 10 .##...###. #..#.#...# .##...###.
output:
2
result:
ok single line: '2'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
11 3 .#. #.# .#. ... .#. #.# .#. ... .#. #.# .#.
output:
3
result:
ok single line: '3'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
20 20 .##.#########....#.. #..#.........####.#. #.....####.........# .#####....#..######. ..........#.#....... .##...####..#..####. #..#.#......#.#....# .#.#.#..####..#..##. ..#...##.....#..#... ....#....####..#.... .###.####.....#..... #............#..###. #...######...#.#...# #..#......##..#....# ...
output:
5
result:
ok single line: '5'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
80 80 .##############################################################################. #..............................................................................# #..##########################################################################..# #.#...................................................
output:
20
result:
ok single line: '20'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
60 80 ..#####....###########.......##..#####.......#######......#############......... .#.....#..#...........##....#..##.....#..#..#.......#....#.............#........ #...###..#..##...#......#....#......#..##.#.#.......#.....####........#......... #..#....#..#..#.#.#..###..##..##...#.#....#.#.........
output:
10
result:
ok single line: '10'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
50 50 .....#########################################.... .####.........................................#... #......#######......########...................##. #.....#.......###..#........#########............# .#....#..........#.#.................######......# ..#....#####.....#..###########...........
output:
1
result:
ok single line: '1'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
80 30 .#...#...#...#...#...#...#.... #.#.#.#.#.#.#.#.#.#.#.#.#.#... .#...#...#...#...#...#...#.... ...#...#...#...#...#...#...#.. ..#.#.#.#.#.#.#.#.#.#.#.#.#.#. ...#...#...#...#...#...#...#.. .#...#...#...#...#...#...#.... #.#.#.#.#.#.#.#.#.#.#.#.#.#... .#...#...#...#...#...#...#.... ...#...#...#......
output:
96
result:
ok single line: '96'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
100 100 ................................................#########........................................... .........................##....................#.........#.......................................... ........................#..#.................##..........#.................#..........###....
output:
11
result:
ok single line: '11'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
100 100 .................................................................................................... ...............................##.........##.....##.....###########................................. .....#######..................#..#.......#..#...#..#...#...........#.........................
output:
25
result:
ok single line: '25'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
50 50 .##.#.#.#.#.#.#.#.#.#.....#.....#.....#.....#..... #..#.#.#.#.#.#.#.#.#.#...#.#...#.#...#.#...#.#.... .#...................#..#...#.#...#.#...#.#...#... #...##.#.#.#.#.#.#..#..#.....#..#..#..#..#.....#.. .#.#..#.#.#.#.#.#.#..#..#......#.#...#.#......#... #...#.............#.#....#...#..#.....#...
output:
19
result:
ok single line: '19'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
100 100 .######.....#####....###################......#############..............################........... #......#...#.....#..#...................#....#.............#####........#................####....... #......#...#....#...#..........######...#....#..#...............##.....#.......####..........
output:
40
result:
ok single line: '40'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
1 1 .
output:
0
result:
ok single line: '0'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
2 2 .. ..
output:
0
result:
ok single line: '0'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
100 100 .................................................................................................... .................................................................................................... .............................................................................................
output:
0
result:
ok single line: '0'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
1 100 ....................................................................................................
output:
0
result:
ok single line: '0'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
100 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
output:
0
result:
ok single line: '0'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
3 100 .#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#.. #.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#. .#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#.....
output:
25
result:
ok single line: '25'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
6 6 .####. #....# #.##.# #..#.# #....# .####.
output:
2
result:
ok single line: '2'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
10 10 .#...#.... #.#.#.#... .#...#..#. ...#...#.# ..#.#...#. ...#..#... .#...#.#.. #.#...#... .#..#...#. ...##...##
output:
8
result:
ok single line: '8'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
20 20 .##.#########....#.. #..#.........####.#. #.....####.........# .#####....#..######. ..........#.#....... .##...####..#..####. #..#.#......#.#....# .#.#.#..####..#..##. ..#...##.....#..#... ....#....####..#.... .###.####.....#..... #............#..###. #...######...#.#...# #..#......##..#..#.# ...
output:
7
result:
ok single line: '7'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
60 80 ..#####....###########.......##..#####.......#######......#############..##.#... .#.....#..#...........##....#..##.....#..#..#.......#....#.............#..#.##.. #...###..#..##...#......#....#......#..##.#.#..##...#.....####........#......... #..#....#..#..#.#.#..###..##..##...#.#....#.#...#.....
output:
52
result:
ok single line: '52'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
50 50 .....#########################################.... .####.........................................#... #......#######......########................#..##. #.....#.......###..#........#########.......##...# .#....#..........#.#.................######......# ..#....#####.....#..###########...........
output:
12
result:
ok single line: '12'