#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp(x, y) (x << 13)+y
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
int n, m, X, Y, ans;
char g[4005][4005];
bool u[4005][4005], t;
queue<int> q[2];
void bfs(){
//cout << "*";
q[0].push(mp(1, 1));
for (ans=0; !q[t].empty(); ans++){
//cout << "*";
while(!q[t].empty()){
//cout << "*";
X=q[t].front() >> 13; Y=q[t].front() &(8191); q[t].pop();
if (u[X][Y]) continue;
u[X][Y]=1;
//cout << X << ' ' << Y << ' ' << g[X][Y]<< endl;
if (!(X+1>n || u[X+1][Y]))
q[(g[X+1][Y]!=g[X][Y]) != t].push(mp(X+1, Y));
if (!(X-1<1 || u[X-1][Y]))
q[(g[X-1][Y]!=g[X][Y]) != t].push(mp(X-1, Y));
if (!(Y+1>m || u[X][Y+1]))
q[(g[X][Y+1]!=g[X][Y]) != t].push(mp(X, Y+1));
if (!(Y-1<1 || u[X][Y-1]))
q[(g[X][Y-1]!=g[X][Y]) != t].push(mp(X, Y-1));
}
t=!t;
}
}
char ch;
int main(){
scanf("%i%i", &n, &m);
fox1(l, n){
ch=getchar();
fox1(l2, m){
g[l][l2]=getchar();
//scanf(" %c", &g[l][l2]);
u[l][l2]=(g[l][l2]=='.');
}
}
bfs();
printf("%i", ans);
return 0;
}
Compilation message
tracks.cpp: In function 'void bfs()':
tracks.cpp:42:51: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
q[(g[X+1][Y]!=g[X][Y]) != t].push(mp(X+1, Y));
^
tracks.cpp:4:19: note: in definition of macro 'mp'
#define mp(x, y) (x << 13)+y
^
tracks.cpp:44:51: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
q[(g[X-1][Y]!=g[X][Y]) != t].push(mp(X-1, Y));
^
tracks.cpp:4:19: note: in definition of macro 'mp'
#define mp(x, y) (x << 13)+y
^
tracks.cpp: In function 'int main()':
tracks.cpp:55:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i", &n, &m);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
33484 KB |
Output is correct |
2 |
Correct |
0 ms |
33352 KB |
Output is correct |
3 |
Correct |
0 ms |
33352 KB |
Output is correct |
4 |
Correct |
6 ms |
33484 KB |
Output is correct |
5 |
Correct |
0 ms |
33352 KB |
Output is correct |
6 |
Correct |
0 ms |
33352 KB |
Output is correct |
7 |
Correct |
0 ms |
33352 KB |
Output is correct |
8 |
Correct |
0 ms |
33352 KB |
Output is correct |
9 |
Correct |
0 ms |
33352 KB |
Output is correct |
10 |
Correct |
3 ms |
33352 KB |
Output is correct |
11 |
Correct |
3 ms |
33352 KB |
Output is correct |
12 |
Correct |
6 ms |
33352 KB |
Output is correct |
13 |
Correct |
3 ms |
33352 KB |
Output is correct |
14 |
Correct |
0 ms |
33352 KB |
Output is correct |
15 |
Correct |
13 ms |
33352 KB |
Output is correct |
16 |
Correct |
23 ms |
33484 KB |
Output is correct |
17 |
Correct |
3 ms |
33352 KB |
Output is correct |
18 |
Correct |
9 ms |
33484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
33352 KB |
Output is correct |
2 |
Correct |
53 ms |
33352 KB |
Output is correct |
3 |
Correct |
306 ms |
33352 KB |
Output is correct |
4 |
Correct |
96 ms |
33352 KB |
Output is correct |
5 |
Correct |
173 ms |
33352 KB |
Output is correct |
6 |
Correct |
1573 ms |
42212 KB |
Output is correct |
7 |
Correct |
3 ms |
33352 KB |
Output is correct |
8 |
Correct |
3 ms |
33352 KB |
Output is correct |
9 |
Correct |
0 ms |
33352 KB |
Output is correct |
10 |
Correct |
0 ms |
33352 KB |
Output is correct |
11 |
Correct |
0 ms |
33352 KB |
Output is correct |
12 |
Correct |
0 ms |
33352 KB |
Output is correct |
13 |
Correct |
53 ms |
33352 KB |
Output is correct |
14 |
Correct |
26 ms |
33352 KB |
Output is correct |
15 |
Correct |
29 ms |
33352 KB |
Output is correct |
16 |
Correct |
29 ms |
33352 KB |
Output is correct |
17 |
Correct |
149 ms |
33352 KB |
Output is correct |
18 |
Correct |
93 ms |
33352 KB |
Output is correct |
19 |
Correct |
76 ms |
33352 KB |
Output is correct |
20 |
Correct |
73 ms |
33352 KB |
Output is correct |
21 |
Correct |
159 ms |
33352 KB |
Output is correct |
22 |
Correct |
186 ms |
33352 KB |
Output is correct |
23 |
Correct |
319 ms |
33352 KB |
Output is correct |
24 |
Correct |
163 ms |
33352 KB |
Output is correct |
25 |
Correct |
486 ms |
33352 KB |
Output is correct |
26 |
Correct |
1669 ms |
33352 KB |
Output is correct |
27 |
Correct |
1816 ms |
35092 KB |
Output is correct |
28 |
Correct |
1776 ms |
42212 KB |
Output is correct |
29 |
Correct |
1779 ms |
40404 KB |
Output is correct |
30 |
Correct |
1446 ms |
40232 KB |
Output is correct |
31 |
Correct |
1219 ms |
33748 KB |
Output is correct |
32 |
Correct |
1493 ms |
34404 KB |
Output is correct |