#include<bits/stdc++.h>
#define db double
#define fo(i,d,c) for(int i=d;i<=c;i++)
#define fod(i,c,d) for(int i=c;i>=d;i--)
#define maxn 1000010
#define N 1010
#define pb push_back
#define en cout<<"\n";
#define inf 1e9
#define pii pair<int,int>
#define vii vector<pii>
#define bit(i,j) ((i>>j)&1)
#define offbit(i,j) (i^(1<<j))
#define onbit(i,j) (i|(j<<1))
#define vi vector<int>
#define vvi vector<vector<int>>
#define checkfile(FiLeNaMe) { if(fopen(FiLeNaMe".inp","r")) freopen(FiLeNaMe".inp","r",stdin),freopen(FiLeNaMe".out","w",stdout); }
using namespace std;
int n,m,ans,d[N][N];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
char a[N][N];
bool safe(int i,int j)
{
return i>0&&j>0&&i<=n&&j<=m;
}
void process()
{
cin>>n>>m;
fo(i,1,n) fo(j,1,m) cin>>a[i][j];
queue<pii> q[2];
int cur=0;//tmp queue
d[1][1]=1;
q[cur].push({1,1});
while(q[0].size()||q[1].size())
{
int u=q[cur].front().first;
int v=q[cur].front().second;
q[cur].pop();
ans=max(ans,d[u][v]);
fo(k,0,3)
{
int U=u+dx[k];
int V=v+dy[k];
if(safe(U,V)&&a[U][V]==a[u][v]&&!d[U][V])
{
d[U][V]=d[u][v];
q[cur].push({U,V});
}
if(safe(U,V)&&a[U][V]==('R'+'F'-a[u][v])&&!d[U][V])
{
d[U][V]=d[u][v]+1;
q[1-cur].push({U,V});
}
}
if(!q[cur].size()) cur^=1;
}
cout<<ans;
}
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);
process();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
3676 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
9 ms |
3544 KB |
Output is correct |
5 |
Correct |
3 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2524 KB |
Output is correct |
11 |
Correct |
3 ms |
2652 KB |
Output is correct |
12 |
Correct |
6 ms |
2652 KB |
Output is correct |
13 |
Correct |
3 ms |
2652 KB |
Output is correct |
14 |
Correct |
3 ms |
2652 KB |
Output is correct |
15 |
Correct |
14 ms |
3628 KB |
Output is correct |
16 |
Correct |
18 ms |
3672 KB |
Output is correct |
17 |
Correct |
10 ms |
3416 KB |
Output is correct |
18 |
Correct |
9 ms |
3704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5468 KB |
Output isn't correct |
2 |
Incorrect |
15 ms |
4212 KB |
Output isn't correct |
3 |
Incorrect |
136 ms |
20200 KB |
Output isn't correct |
4 |
Incorrect |
32 ms |
6224 KB |
Output isn't correct |
5 |
Incorrect |
76 ms |
13396 KB |
Output isn't correct |
6 |
Incorrect |
134 ms |
20184 KB |
Output isn't correct |
7 |
Runtime error |
6 ms |
10588 KB |
Execution killed with signal 11 |
8 |
Incorrect |
2 ms |
5336 KB |
Output isn't correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
11 |
Runtime error |
6 ms |
10680 KB |
Execution killed with signal 11 |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Incorrect |
17 ms |
4436 KB |
Output isn't correct |
14 |
Correct |
31 ms |
5724 KB |
Output is correct |
15 |
Correct |
21 ms |
6488 KB |
Output is correct |
16 |
Incorrect |
15 ms |
3164 KB |
Output isn't correct |
17 |
Incorrect |
35 ms |
6512 KB |
Output isn't correct |
18 |
Incorrect |
36 ms |
6508 KB |
Output isn't correct |
19 |
Incorrect |
32 ms |
6224 KB |
Output isn't correct |
20 |
Incorrect |
29 ms |
5980 KB |
Output isn't correct |
21 |
Incorrect |
84 ms |
13664 KB |
Output isn't correct |
22 |
Incorrect |
77 ms |
13396 KB |
Output isn't correct |
23 |
Incorrect |
66 ms |
12112 KB |
Output isn't correct |
24 |
Incorrect |
83 ms |
13396 KB |
Output isn't correct |
25 |
Incorrect |
147 ms |
20188 KB |
Output isn't correct |
26 |
Correct |
103 ms |
16472 KB |
Output is correct |
27 |
Incorrect |
134 ms |
20192 KB |
Output isn't correct |
28 |
Incorrect |
138 ms |
20192 KB |
Output isn't correct |
29 |
Incorrect |
138 ms |
20192 KB |
Output isn't correct |
30 |
Incorrect |
132 ms |
19796 KB |
Output isn't correct |
31 |
Incorrect |
87 ms |
14676 KB |
Output isn't correct |
32 |
Incorrect |
139 ms |
20192 KB |
Output isn't correct |