#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<int,int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
const int N = 4e3+10;
char a[N][N];
int visited[N][N];
queue<pi> q;
int main()
{
cin.tie(0)->sync_with_stdio(0);
int r,c;cin >> r >> c;
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
cin >> a[i][j];
}
}
visited[1][1] = 1;
q.push({1,1});
set<char> ans;
while(sz(q)){
int ni = q.front().first,nj = q.front().second;
ans.insert(a[ni][nj]);
q.pop();
for(int i=-1;i<=1;i++) for(int j=-1;j<=1;j++){
if(abs(i) == abs(j)) continue;
int ii = ni+i,jj = nj+j;
if(ii < 1 || ii > r || jj < 1 || jj > c) continue;
if(visited[ii][jj]) continue;
visited[ii][jj] = 1;
q.push({ii,jj});
}
}
cout << sz(ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
5368 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
724 KB |
Output isn't correct |
4 |
Incorrect |
11 ms |
4892 KB |
Output isn't correct |
5 |
Incorrect |
8 ms |
3024 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
1108 KB |
Output isn't correct |
10 |
Incorrect |
5 ms |
2644 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
2072 KB |
Output isn't correct |
12 |
Incorrect |
6 ms |
2964 KB |
Output isn't correct |
13 |
Incorrect |
6 ms |
3028 KB |
Output isn't correct |
14 |
Incorrect |
6 ms |
3028 KB |
Output isn't correct |
15 |
Incorrect |
26 ms |
5528 KB |
Output isn't correct |
16 |
Incorrect |
16 ms |
5332 KB |
Output isn't correct |
17 |
Incorrect |
16 ms |
5224 KB |
Output isn't correct |
18 |
Incorrect |
15 ms |
4896 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
30932 KB |
Output isn't correct |
2 |
Incorrect |
94 ms |
17932 KB |
Output isn't correct |
3 |
Incorrect |
1172 ms |
94484 KB |
Output isn't correct |
4 |
Incorrect |
250 ms |
33496 KB |
Output isn't correct |
5 |
Incorrect |
646 ms |
68052 KB |
Output isn't correct |
6 |
Incorrect |
1155 ms |
94576 KB |
Output isn't correct |
7 |
Incorrect |
17 ms |
32204 KB |
Output isn't correct |
8 |
Incorrect |
16 ms |
30924 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
592 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
11 |
Incorrect |
18 ms |
31696 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
1620 KB |
Output isn't correct |
13 |
Incorrect |
98 ms |
17904 KB |
Output isn't correct |
14 |
Incorrect |
53 ms |
11852 KB |
Output isn't correct |
15 |
Incorrect |
62 ms |
13052 KB |
Output isn't correct |
16 |
Incorrect |
49 ms |
6592 KB |
Output isn't correct |
17 |
Incorrect |
271 ms |
36052 KB |
Output isn't correct |
18 |
Incorrect |
262 ms |
35736 KB |
Output isn't correct |
19 |
Incorrect |
244 ms |
33680 KB |
Output isn't correct |
20 |
Incorrect |
252 ms |
30996 KB |
Output isn't correct |
21 |
Incorrect |
662 ms |
70308 KB |
Output isn't correct |
22 |
Incorrect |
675 ms |
67992 KB |
Output isn't correct |
23 |
Incorrect |
529 ms |
56928 KB |
Output isn't correct |
24 |
Incorrect |
639 ms |
69660 KB |
Output isn't correct |
25 |
Incorrect |
1133 ms |
94512 KB |
Output isn't correct |
26 |
Correct |
827 ms |
81016 KB |
Output is correct |
27 |
Incorrect |
1130 ms |
94464 KB |
Output isn't correct |
28 |
Incorrect |
1082 ms |
94476 KB |
Output isn't correct |
29 |
Incorrect |
1027 ms |
94376 KB |
Output isn't correct |
30 |
Incorrect |
1054 ms |
92552 KB |
Output isn't correct |
31 |
Incorrect |
699 ms |
73168 KB |
Output isn't correct |
32 |
Incorrect |
1121 ms |
94420 KB |
Output isn't correct |